java实现将文件内容导入到数据库中

来源:互联网 发布:淘宝上有没有卖视频的 编辑:程序博客网 时间:2024/06/10 16:29


1、文件格式形如:6|1|2|3|14


2、写一个ctl文件,项目中此文件也可以从数据库读取值写入到文件中。


文件内容如下:

LOAD DATA infile 'C:\file\local\APPLY_20150612.txt' append into table TMP_LOAD_DATA fields terminated by '|' trailing nullcols (  CUST_NAME        "trim(:CUST_NAME)",  BATCH_CODE       "trim(:BATCH_CODE)")

3、写bat文件

SQLLDR userid=username/password@orcl CONTROL=D:\workspace\temp\LOAD20150612.ctl  LOG=C:\temp_log.log errors=2000pause

4、写java类调用bat文件

public class InvokeBat {      public void runbat(String batName) {          try {              Process ps = Runtime.getRuntime().exec(batName);                          ps.waitFor();            } catch (IOException ioe) {              ioe.printStackTrace();          } catch (InterruptedException e) {              e.printStackTrace();          }      }        //测试执行bat    public static void main(String[] args) {          InvokeBat2 test1 = new InvokeBat2();          String batName = "D:\\workspace\\shell\\file2db.bat";          test1.runbat(batName);          System.out.println("main thread");      }  }  

5、如此,文件中的数据就会存入到数据库表中。

0 0