我有一个带有代码的 Java 程序:
public class Test1 {
public static void main(String args[]) throws InterruptedException,
IOException {
String cmd = "cmd /c start test.bat";
Process p = Runtime.getRuntime().exec(cmd);
InputStream stderr = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
System.out.println(line);}
p.waitFor();
int exitVal = p.exitValue();
System.out.println(exitVal);
} }
test.bat 执行另一个具有以下代码的程序:
public class ConnectionTest {
public Connection getConn throws SQLException{
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String driverName = "com.ibm.db2.jcc.DB2Driver22222";
try {
Class.forName(driverName).newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
;;;; ;;;; ;;; ;;;
但是从Test1来看,exit值总是0。怎么来的,当批处理执行时,它将运行ConnectionTest类,它会因为找不到DB2Driver22222而出现异常。
谁能向我解释为什么我没有得到正确的错误代码或任何错误消息。