我正在尝试通过java程序使用sql loader在oracle数据库中加载一个csv文件。我已经通过运行命令成功执行了它,但是我想通过 java 程序将 csv 文件数据加载到数据库中。我的程序是:
加载CSV.csv:
ID,firstName,LastName,Address 1,aditya,kumar,gaya 2,abhijeet,chanda,kol 3,Rahul,Jordar,kol
试用.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(); } } }
它已编译并成功运行,但未在数据库中插入任何数据。非常感谢您的建议。提前谢谢。