自动生成clt的sqlload文件

 1 public static void execSqlLoad(String cvsPath) throws IOException {
 2 
 3         String infileStr = "infile ";
 4         String ext = "";
 5         boolean flag = false;
 6 
 7         String[] myList;
 8         File file = new File(cvsPath);
 9         myList = file.list();
10 
11         for (int i = 0; i < myList.length; i++) {
12             if (null != file.getName() && !"".equals(file.getName())) {
13                 ext = myList[i].substring(myList[i].lastIndexOf(".") + 1,
14                         myList[i].length() - myList[i].lastIndexOf(".") + 1);
15                 if ("csv".equalsIgnoreCase(ext)) {
16                     flag = true;
17                     stringBuffer.append("\r\n");
18                     stringBuffer.append(infileStr + "'" + csvPath + myList[i]
19                             + "'");
20                 }
21             }
22         }
23 
24         stringBuffer.append("\r\n");
25         stringBuffer.append("into table ");
26         stringBuffer.append("\"" + tableName + "\"");
27         stringBuffer.append("\r\n");
28         stringBuffer.append("fields terminated by ','");
29         stringBuffer.append("\r\n");
30         stringBuffer
31                 .append("(BAR_CD_NO,EXT_SLIP_TYPE,PDF_NAME,PDF_PATH,NUMBERING,PDF_PAGE_NO,BOX_NO)");
32 
33         wirte(stringBuffer.toString());
34 
35         if (flag) {
36             System.out.println(sqlload);
37             Process ldr = Runtime.getRuntime().exec(sqlload);
38             InputStream stderr = ldr.getInputStream();
39             InputStreamReader isr = new InputStreamReader(stderr);
40             BufferedReader br = new BufferedReader(isr);
41             String line = null;
42 
43             while (br.readLine() != null) {
44                 line = br.readLine();
45                 System.out.println(line);
46             }
47 
48             stderr.close();
49             isr.close();
50             br.close();
51             ldr.destroy();
52         }
53     }

遍历csv文件夹下所有csv数据文件,并自动生成ctl控制文件

转载于:https://www.cnblogs.com/allenzh/archive/2012/07/12/2588530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值