我試圖通過加載Java程序使用SQL裝載機在Oracle數據庫csv文件。我已經成功地通過運行命令執行它,但我想通過Java程序在數據庫中加載csv文件數據。我的方案是:加載csv文件數據到oracle數據庫
loadCsv.csv:
ID,firstName,LastName,Address 1,aditya,kumar,gaya 2,abhijeet,chanda,kol 3,Rahul,Jordar,kol
trial.ctl:
LOAD DATA INFILE loadCsv.csv BADFILE trial.bad DISCARDFILE trial.dsc APPEND INTO TABLE load1 FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY "」" (x,y,z,t)
SqlLoaderTest.java:
public class SqlLoaderTest { public static void main(String[] args) { try { String sqlldrCmd = "sqlldr control=E:\\load_data\\trial.ctl"+ "LOG=trial.log "+ "DATA=E:\\load_data\\loadCsv.csv USERID=vehere/adi"+ "BAD=E:\\load_data\\trial.bad"; System.out.println("SQLLDR Started ....... "); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(sqlldrCmd); System.out.println("SQLLDR Ended ........ "); } catch (Exception e) { e.printStackTrace(); } } }
它已成功編譯並運行,但未在數據庫中插入任何數據。您的建議非常感謝。提前告知。