通过JAVA加载时出现SQLLoader 704内部错误

时间:2019-04-09 07:31:22

标签: java oracle sql-loader

在执行sqlldr命令时出现以下错误。

SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
ORA-12154: TNS:could not resolve the connect identifier specified

以下是sqlldr cmd:

sqlldr BILLING/'"Bill!ng@123#"'@10.113.242.162:1521/bssstc control=/log/bssuser/CDR/Postpaid_CDR_Log/CTRL_File.ctrl log=/log/bssuser/CDR/Postpaid_CDR_Log/LOG_File.log direct=false silent=header skip_unusable_indexes=true rows=200000 bindsize=20000000 readsize=20000000 ERRORS=25000

注意:-通过命令执行相同命令时,它会成功。

以下是我尝试过的代码段。

            Runtime rt   = Runtime.getRuntime();
            Process proc = null;
            try {
                proc = rt.exec(sqlLoaderCommand);

                InputStream       stderr = proc.getErrorStream();
                InputStreamReader isr    = new InputStreamReader(stderr);
                BufferedReader    br     = new BufferedReader(isr);

                String line = null;
                while ((line = br.readLine()) != null){
                    logger.info(line);
                }
                int exitVal = proc.waitFor();
                logger.info("Process exitValue: " + exitVal);
                int returnValue = proc.exitValue();
                String str = null;

                if (returnValue != 0) {
                    InputStream in = proc.getInputStream();
                    InputStreamReader preader = new InputStreamReader(in);
                    BufferedReader breader = new BufferedReader(preader);
                    String msg = null;
                    while ((msg = breader.readLine()) != null) {
                        logger.info(msg);
                        str = str + msg;
                    }
                    System.out.flush();
                    preader.close();
                    breader.close();
                    in.close();
                    InputStream inError = proc.getErrorStream();
                    InputStreamReader preaderError = new InputStreamReader(inError);
                    BufferedReader breaderError = new BufferedReader(preaderError);


                    String errorMsg = null;
                    while ((errorMsg = breaderError.readLine()) != null) {
                        logger.info("Copy Error: " + errorMsg);
                        str = str + errorMsg;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }

2 个答案:

答案 0 :(得分:1)

我认为您的用户名-“ Bill!ng @ 123#”中可能存在错误。在Java中查看引号转义规则。喜欢:

String str = "BILLING/'\"Bill!ng@123#\"'@10.113.242.162:1521";

答案 1 :(得分:0)

1)从命令行尝试执行tnsping 10.113.242.162 如果该工具将返回完整的描述,则必须在Java中设置“ oracle.net.tns_admin”。

System.setProperty("oracle.net.tns_admin", "ORACLE_DIRECTORY/network/admin");-在此处放置正确的路径,然后在代码之前执行

2)为了进行测试,您可以尝试使用完整的连接描述。

代替10.113.242.162:1521/bssstc->

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.113.242.162)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=bssstc))