当前位置: 代码迷 >> Oracle开发 >> 哪位高手有java实现csv文件导入orcale数据库的例子
  详细解决方案

哪位高手有java实现csv文件导入orcale数据库的例子

热度:100   发布时间:2016-04-24 07:48:33.0
谁有java实现csv文件导入orcale数据库的例子
就是可以根据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>
  相关解决方案