我正在尝试在Unix上通过Java运行SQL*Loader。
我正在使用以下命令,当我在命令行 (bash) 上运行它时它可以工作:
sqlldr userid=user/pass@"(DESCRIPTION = (SDU = xxxx) (TDU = xxxx) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxxx)(PORT = xxxx)) (LOAD_BALANCE = on) (FAILOVER = on ) )(CONNECT_DATA = (SERVICE_NAME = xxxx) ))" control='xxxx' log='xxxx' readsize=xxxx streamsize=xxxx
我正在使用转义来在没有tnsnames.ora
文件的情况下运行它。
这是我在 Java 代码中的翻译方式:
String unixCmd = "sqlldr userid=user/pass@\"\(DESCRIPTION = \(SDU = xxxx\) \(TDU = xxxx\) \(ADDRESS_LIST = \(ADDRESS = \(PROTOCOL = TCP\)\(HOST = xxxx\)\(PORT = xxxx\)\) \(LOAD_BALANCE = on\) \(FAILOVER = on \) \)\(CONNECT_DATA = \(SERVICE_NAME = xxxx\) \)\)\" control='xxxx' log='xxxx' readsize=xxxx streamsize=xxxx";
System.out.println(unixCmd);
p = Runtime.getRuntime().exec(unixCmd);//not working
p = Runtime.getRuntime().exec("sh -c "+unixCmd);//not working
我收到以下错误消息:
LRM-00116: syntax error at 'user/pass' following '='
SQL*Loader: Release 11.2.0.2.0 - Production on Wed Jun 1 11:29:59 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
我做错了什么?
你太逃避了。在 shell 脚本中,您需要转义括号,因为您不希望 shell 本身解释这些括号;在 Java 字符串中,您不会:
String unixCmd = "sqlldr userid=user/pass@"(DESCRIPTION = (SDU = xxxx) (TDU = xxxx) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = xxxx)) (LOAD_BALANCE = on) (FAILOVER = on ) )(CONNECT_DATA = (SERVICE_NAME = xxxx) ))" control='xxxx' log='xxxx' readsize=xxxx streamsize=xxxx";
System.out.println(unixCmd);
p = Runtime.getRuntime().exec(unixCmd);
只有双引号需要转义。使用此代码,它不会获得LRM-00116。使用您的虚拟值,它当然仍然会出错 - 最初在LRM-00104: 'xxxx' is not a legal integer for 'readsize'
上,但输入实际值表明它按预期工作。