就是可以根据csv文件更新数据库表的例子
新学java
大家HELP一下
------解决方案--------------------
http://community.csdn.net/Expert/topic/5545/5545983.xml?temp=.8464472
http://www.cnoug.org/archiver/tid-69965.html
------解决方案--------------------
test.txt内容如下
"10 ", "mm "
"20 ", "nn "
----------------
aa.java,自动生成控制文件test.ctl并且导入到oracle
import java.io.*;
import java.text.*;
import java.util.*;
public class aa
{
public static void main(String[] args) throws Exception
{
BufferedWriter bw = new BufferedWriter(new FileWriter( "test.ctl ",false));
bw.write( "load data\r\n ");
bw.write( "infile 'test.txt '\r\n ");
bw.write( "truncate into table test\r\n ");
bw.write( "fields terminated by ', ' enclosed by '\ " '\r\n ");
bw.write( "trailing nullcols\r\n ");
bw.write( "(id,name)\r\n ");
bw.close();
Process proc=Runtime.getRuntime().exec( "sqlldr.exe userid=system/manager control=test.ctl ");
proc.waitFor();
}
}
SQL> desc test
名称 是否为空? 类型
----------------------------------------- -------- -------------
ID NUMBER
NAME VARCHAR2(10)
SQL> select * from test;
未选定行
SQL>
E:\java> javac aa.java
E:\java> java aa
SQL> select * from test;
ID NAME
---------- ----------
10 mm
20 nn
SQL>