python调用sqlldr_Java调Runtime在Linux命令行执行sqlldr失败

我们的一个项目采用SQL*Loader的方法将数据导入Oracle数据库。主要方法是Java写好控制文件拼接好sqlldr命令字符串,通过Runtime类在终端命令行执行。以下是执行命令的方法;

public String executeImport(String user, String password, String database,String fileRoute, String ctlfileName,

String logsRoute,String logfileName) {

InputStream ins = null;

String dos = "sqlldr " + user + "/" + password + "@" + database + " control=" + fileRoute + ctlfileName + " log=" + logsRoute + logfileName;

String returnCode = "0";

try {

Process process = Runtime.getRuntime().exec(dos);

ins = process.getInputStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(ins));

String line = null;

while ((line = reader.readLine()) != null) {

String msg = new String(line.getBytes("ISO-8859-1"), "UTF-8");

}

int exitValue = process.waitFor();

process.getOutputStream().close();

reader.close();

ins.close();

} catch (Exception e) {

return "-1";

}

return returnCode;

}

但是在执行的时候报错了,java.io.IOException: Cannot run program "sqlldr": error=2, A file or directory in the path name does not exist,具体的报错信息如下;

java.io.IOException: Cannot run program "sqlldr": error=2, A file or directory in the path name does not exist.

at java.lang.ProcessBuilder.processException(ProcessBuilder.java:489)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)

at java.lang.Runtime.exec(Runtime.java:604)

at java.lang.Runtime.exec(Runtime.java:442)

at java.lang.Runtime.exec(Runtime.java:339)

at com.sdb.bbcp.common.SqlldrImportDataFile.executeImport(SqlldrImportDataFile.java:188)

at com.sdb.bbcp.common.SqlldrImportDataFile.execute(SqlldrImportDataFile.java:80)

at com.sdb.common.flow.SDBEMPFlow.execute(SDBEMPFlow.java:175)

at com.ecc.emp.flow.Operation.execute(Operation.java:96)

at com.ecc.emp.flow.EMPBusinessLogic.execute(EMPBusinessLogic.java:89)

at com.ecc.emp.processor.EMPBusinessLogicCaller.execute(EMPBusinessLogicCaller.java:112)

at com.sdb.common.flow.SDBEMPFlow.execute(SDBEMPFlow.java:175)

at com.ecc.emp.flow.Operation.execute(Operation.java:96)

at com.ecc.emp.flow.EMPBusinessLogic.execute(EMPBusinessLogic.java:89)

at com.ecc.emp.processor.EMPBusinessLogicCaller.execute(EMPBusinessLogicCaller.java:112)

at com.sdb.common.flow.SDBEMPFlow.execute(SDBEMPFlow.java:175)

at com.ecc.emp.flow.Operation.execute(Operation.java:96)

at com.ecc.emp.flow.EMPBusinessLogic.execute(EMPBusinessLogic.java:89)

at com.sdb.bbcp.communication.BBCPTCPIPRequestService.handleRequest(BBCPTCPIPRequestService.java:190)

at com.sdb.bbcp.communication.BBCPTCPIPServiceServlet.processNewPackage(BBCPTCPIPServiceServlet.java:505)

at com.ecc.emp.tcpip.TCPIPService.processNewPackage(TCPIPService.java:652)

at com.ecc.emp.tcpip.TCPIPService.newPackageReceived(TCPIPService.java:567)

at com.ecc.emp.tcpip.SocketProcessThread.runTask(SocketProcessThread.java:127)

at com.ecc.emp.tcpip.SocketProcessThread.run(SocketProcessThread.java:107)

at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)

at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)

at java.lang.Thread.run(Thread.java:784)

随后我查找了网上大多数相似问题,尝试检查了环境变量,将命令写到shell再调shell执行,结果还是失败了,以下是一些环境信息(..是省略的意思);

Server:AIX 7.1.0.0

$ORACLE_HOME=/oracle/.../product/10.2.0

$PATH=.:$ORACLE_HOME/bin:.

chown -R username /oracle/

User Groups: staff system dba

P.S. 该程序在我们另外两台服务器上能够正常执行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值