gpt4 book ai didi

java.io.IOException : Cannot run program "sqlldr": CreateProcess error=2, 系统找不到指定的文件

转载 作者:行者123 更新时间:2023-12-02 08:04:10 27 4
gpt4 key购买 nike

已经在 J​​SF 操作 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();
}
}
}

谢谢...

最佳答案

问题出在您的代码上。

最好使用“cmd.exe/C”并指定环境变量。

最好的方法是 exec(String[] cmdarray, String[] envp, File dir)。你可以查看java文档。

关于java.io.IOException : Cannot run program "sqlldr": CreateProcess error=2, 系统找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8430590/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com