我使用process = Runtime.getRuntime().exec(cmd,null,new File(path));
以执行文件中的一些SQL(abz.sql)问题与运行调用Runtime.getRuntime(时)EXEC
命令是:
"sqlplus "+ context.getDatabaseUser() + "/"
+ context.getDatabasePassword() + "@"
+ context.getDatabaseHost() + ":"
+ context.getDatabasePort() + "/"
+ context.getSid() + " @"
+ "\""
+ script + "\"";
String path=context.getReleasePath()+ "/Server/DB Scripts";
据执行该文件,但没有退出。因此我尝试使用:
Writer out = new OutputStreamWriter(process.getOutputStream());
out.append("commit;\r\n");
out.append("exit \r\n");
System.out.println("---------"+out);
out.close();
此它完整块我米使用:
if(context.getConnectionField()=="ORACLE")
{
String cmd=
"sqlplus "+ context.getDatabaseUser() + "/"
+ context.getDatabasePassword() + "@"
+ context.getDatabaseHost() + ":"
+ context.getDatabasePort() + "/"
+ context.getSid() + " @"
+ "\""
+ script +"\"";
String path=context.getReleasePath()+ "/Server/DB Scripts";
process = Runtime.getRuntime().exec(cmd,null,new File(path));
out = new OutputStreamWriter(process.getOutputStream());
out.append("commit;\r\n");
out.append("exit \r\n");
System.out.println("---------"+out);
out.close();
Integer result1 = null;
while (result1 == null) {
try {
result1 = process.waitFor();
}
catch (InterruptedException e) {}
}
if(process.exitValue() != 0)
return false;
return true;
}
如果您认真对待此问题,请考虑其他人如何阅读您的问题;你的问题格式不好,很难为其他人阅读。通常,这会导致低质量的答案或根本没有答案。如果你想正确回答你的问题,请尝试写下你的问题:) – 2011-05-03 14:38:15
它以什么方式不起作用?你没有得到你期望的结果,或者你是否遇到异常情况等? – karakuricoder 2011-05-03 14:43:06