java.io.IOException: 无法运行程序“sqlldr”: CreateProcess error=2,系统找不到指定的文件
在 JSF 操作 bean 中编写了一个方法,该方法将执行 sqlldr 命令,但问题是在“Process”处出现错误。
但是当我将其作为独立的 Java 程序尝试时,相同的代码可以正常工作并将数据加载到表中。
注意:Oracle 和 java 路径也已设置...
需要帮助...:(
下面是我的代码:
Action Bean 中的方法将在按钮单击时调用
public String executeControlFile() {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("sqlldr userid=system/root control=d:\\emp\\emp.ctl log=d:\\emp\\empNew2.log");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
错误:
16:55:17,436 ERROR [STDERR] java.io.IOException: Cannot run program "sqlldr": CreateProcess error=2, The system cannot find the file specified
16:55:17,444 ERROR [STDERR] at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
16:55:17,445 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:593)
16:55:17,447 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:431)
16:55:17,448 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:328)
16:55:17,449 ERROR [STDERR] at com.cimm.actionBean.SqlLoaderBean.executeControlFile(SqlLoaderBean.java:134)
16:55:17,450 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
16:55:17,451 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
16:55:17,452 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
16:55:17,453 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
16:55:17,454 ERROR [STDERR] at org.apache.el.parser.AstValue.invoke(AstValue.java:170)
16:55:17,456 ERROR [STDERR] at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
16:55:17,457 ERROR [STDERR] at org.richfaces.ui.application.StateMethodExpressionWrapper.invoke(StateMethodExpressionWrapper.java:76)
16:55:17,459 ERROR [STDERR] at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
16:55:17,460 ERROR [STDERR] at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
16:55:17,461 ERROR [STDERR] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
16:55:17,462 ERROR [STDERR] at javax.faces.component.UICommand.broadcast(UICommand.java:311)
16:55:17,463 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
16:55:17,464 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)
16:55:17,464 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
16:55:17,465 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)
16:55:17,465 ERROR [STDERR] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
16:55:17,466 ERROR [STDERR] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
16:55:17,466 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
16:55:17,467 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
16:55:17,467 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
16:55:17,468 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,468 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
16:55:17,469 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
16:55:17,469 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
16:55:17,470 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
16:55:17,470 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
16:55:17,471 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,471 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
16:55:17,472 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
16:55:17,472 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,473 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
16:55:17,473 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
16:55:17,474 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
16:55:17,474 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
16:55:17,475 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
16:55:17,475 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
16:55:17,476 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
16:55:17,477 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
16:55:17,477 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
16:55:17,478 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
16:55:17,478 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
16:55:17,479 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
16:55:17,479 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
16:55:17,480 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
16:55:17,480 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
16:55:17,480 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
16:55:17,481 ERROR [STDERR] Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
16:55:17,482 ERROR [STDERR] at java.lang.ProcessImpl.create(Native Method)
16:55:17,482 ERROR [STDERR] at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
16:55:17,483 ERROR [STDERR] at java.lang.ProcessImpl.start(ProcessImpl.java:30)
16:55:17,483 ERROR [STDERR] at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
16:55:17,483 ERROR [STDERR] ... 50 more
独立的 Java 程序运行良好,没有任何障碍
public class Main {
public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("sqlldr userid=system/root control=d:\\emp\\configuration.ctl log=d:\\emp\\configuration.log");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
谢谢...
Have written a method in JSF action bean which 'll execute sqlldr command, but the thing is am getting error at "Process".
But the same code work fine and load the data into a table when i tried it as a stand alone Java program.
note: Oracle and java path is also been set....
need help... :(
Below are my code:
method in Action Bean which will be called on Button click
public String executeControlFile() {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("sqlldr userid=system/root control=d:\\emp\\emp.ctl log=d:\\emp\\empNew2.log");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Error :
16:55:17,436 ERROR [STDERR] java.io.IOException: Cannot run program "sqlldr": CreateProcess error=2, The system cannot find the file specified
16:55:17,444 ERROR [STDERR] at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
16:55:17,445 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:593)
16:55:17,447 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:431)
16:55:17,448 ERROR [STDERR] at java.lang.Runtime.exec(Runtime.java:328)
16:55:17,449 ERROR [STDERR] at com.cimm.actionBean.SqlLoaderBean.executeControlFile(SqlLoaderBean.java:134)
16:55:17,450 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
16:55:17,451 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
16:55:17,452 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
16:55:17,453 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
16:55:17,454 ERROR [STDERR] at org.apache.el.parser.AstValue.invoke(AstValue.java:170)
16:55:17,456 ERROR [STDERR] at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
16:55:17,457 ERROR [STDERR] at org.richfaces.ui.application.StateMethodExpressionWrapper.invoke(StateMethodExpressionWrapper.java:76)
16:55:17,459 ERROR [STDERR] at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
16:55:17,460 ERROR [STDERR] at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
16:55:17,461 ERROR [STDERR] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
16:55:17,462 ERROR [STDERR] at javax.faces.component.UICommand.broadcast(UICommand.java:311)
16:55:17,463 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
16:55:17,464 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)
16:55:17,464 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
16:55:17,465 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)
16:55:17,465 ERROR [STDERR] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
16:55:17,466 ERROR [STDERR] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
16:55:17,466 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
16:55:17,467 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
16:55:17,467 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
16:55:17,468 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,468 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
16:55:17,469 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
16:55:17,469 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
16:55:17,470 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
16:55:17,470 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
16:55:17,471 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,471 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
16:55:17,472 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
16:55:17,472 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
16:55:17,473 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
16:55:17,473 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
16:55:17,474 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
16:55:17,474 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
16:55:17,475 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
16:55:17,475 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
16:55:17,476 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
16:55:17,477 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
16:55:17,477 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
16:55:17,478 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
16:55:17,478 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
16:55:17,479 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
16:55:17,479 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
16:55:17,480 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
16:55:17,480 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
16:55:17,480 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
16:55:17,481 ERROR [STDERR] Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
16:55:17,482 ERROR [STDERR] at java.lang.ProcessImpl.create(Native Method)
16:55:17,482 ERROR [STDERR] at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
16:55:17,483 ERROR [STDERR] at java.lang.ProcessImpl.start(ProcessImpl.java:30)
16:55:17,483 ERROR [STDERR] at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
16:55:17,483 ERROR [STDERR] ... 50 more
And the Stand alone Java Program which is working Fine without any hurdle
public class Main {
public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("sqlldr userid=system/root control=d:\\emp\\configuration.ctl log=d:\\emp\\configuration.log");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
Thank you...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题来自于你的代码。
最好使用“cmd.exe /C”并指定环境变量。
最好的方法是 exec(String[] cmdarray, String[] envp, File dir)。你可以查看java文档。
The problem comes from your code.
It's much better to use "cmd.exe /C " and and specify environment variables.
The best method is exec(String[] cmdarray, String[] envp, File dir). You can check java documentation.