oracle - Java调Runtime在Linux命令行执行sqlldr失败

 mobiledu2502863997 发布于 2022-10-25 11:09

我们的一个项目采用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. 该程序在我们另外两台服务器上能够正常执行。

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有