自动生成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控制文件

posted @ 2012-07-12 17:52  码代码微信  阅读(317)  评论(0编辑  收藏  举报