java - How do I read a CSV file into my local Oracle Database table? -
my goal read csv file, loading sample database table (oracle) have . far , have following java code :
public class parsingcsv { public static void main(string[] args) { parsingcsv obj = new parsingcsv(); obj.run(); } @suppresswarnings("oracle.jdeveloper.java.nested-assignment") public void run() { string csvfile = "c:\\users\\ibm_admin\\desktop\\work\\connectone_bancorp\\database_work\\book1.csv"; bufferedreader br = null; string line = ""; string cvssplitby = ","; try { br = new bufferedreader(new filereader(csvfile)); while ((line = br.readline()) != null) { // use comma separator string[] country = line.split(cvssplitby); system.out.println("country [code= " + country[4] + " , name=" + country[5] + "]"); } } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } { if (br != null) { try { br.close(); } catch (ioexception e) { e.printstacktrace(); /* boilerplate */
any tips/pointers appreciated , !
the tips be:
download oracle database driver oracle driver
set .jar classpath. [java setting class path]
register driver , connect database [java connect oracle]
execute sql "create table...." [sql create table example]
for every line read sql = "insert into..." [sql insert example]
for every step if need more example , advice, suggest google use [] tags search
Comments
Post a Comment