java代码:
.....
Runtime rt = Runtime.getRuntime();
Process p = null;
String command = "db2cmd -c -w -i C:/import1.bat";
p = rt.exec(command);
p.waitFor();
.....
import1.bat:
@echo off
db2 connect to text_DB user text using tesxt0114
db2 IMPORT FROM "C:\MVCMSInputFiles\IIS20121224180129.csv" OF DEL METHOD P (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) MESSAGES "C:\MVCMSInputFiles\20121224180129.log" INSERT INTO BLUEX.BIZ_MACHINE (MACHINE_SSERIALNO, MACHINE_STYPE, MACHINE_SPROJECTID, MACHINE_SCATEGORY, MACHINE_SNAME, MACHINE_SBRAND, MACHINE_SSPOT, MACHINE_SPRODUCEDATE, MACHINE_SSERVPERIOD, MACHINE_SENDDATE, MACHINE_SCONTRACTID, MACHINE_SSERVSTATUS, MACHINE_NSTATUS, MACHINE_SSCID, LOG_SLASTUSER, MACHINE_TSIMPORTTIME)
db2 connect reset
<小时/> 我还使用
p.getInputStream()
来处理InputStream
,但该过程始终被第3个命令阻止(db2 import.....)
javacode:
Runtime rt = Runtime.getRuntime();
Process p = null;
String command = "db2cmd -c -w -i C:/import1.bat";
p = rt.exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = reader.readLine())!= null){
System.out.println(line);
}
reader.close();
while(true){
if (p.waitFor() == 0) break;
}
当我使用db2 export...
或db2 select * from ....
替换第3个命令时。函数waitfor
可以返回结果。这个过程不能阻止。
太奇怪了。
答案 0 :(得分:0)
也许你可以这样做:
Runtime rt = Runtime.getRuntime();
Process p = null;
String command = "db2cmd -c -w -i C:/import1.bat";
p = rt.exec(command);
p.getInputStream().close();
p.waitFor();
帮助可以帮到你。
答案 1 :(得分:0)
我得到了关于这个问题的答案。 原因是: 在p = rt.exec(命令)之前,存在未提交的连接对象。 所以这样的代码可以正常运行。
.... ...
ConnectionFactory.commit(conn);
p = rt.exec(command);
... ....