我不知道为什么在以下代码中使用绑定变量会失败,但是硬编码可以工作。
如果我只是放置rownum < 2
子句而不是id子句,它也可以工作。
无:使用绑定变量在代码的其他部分也可以正常工作。
Oracle 12c
ID列是VARCHAR2(34)。
org.apache.commons.dbutils.QueryRunner remote = ...;
String searchId = "13056899429626141414864120X"
String sql = toString("SELECT * FROM ", remoteOwner, ".table_name WHERE id = '"+searchId+"'");
result = remote.query(sql, new MapListHandler());
org.apache.commons.dbutils.QueryRunner remote = ...;
String searchId = "13056899429626141414864120X"
String sql = toString("SELECT * FROM ", remoteOwner, ".table_name WHERE id = ?");
result = remote.query(sql, new MapListHandler(), searchId);
Exception in thread "main" java.sql.SQLException: ORA-00972: identifier is too long
Query: SELECT * FROM SCHEMA_NAME.table_name WHERE id = ? Parameters: [13056899429626141414864120X]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:527)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:391)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:329)
java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1018)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Odscrarr.doODNY(T4C8Odscrarr.java:96)
at oracle.jdbc.driver.T4CPreparedStatement.doDescribe(T4CPreparedStatement.java:717)
at oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:4404)
at oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:52)
at oracle.jdbc.driver.OracleStatement.getResultSetMetaData(OracleStatement.java:4387)
at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(OraclePreparedStatement.java:5581)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getMetaData(OraclePreparedStatementWrapper.java:1509)
at oracle.jdbc.driver.OracleParameterMetaData.getParameterMetaData(OracleParameterMetaData.java:70)
at oracle.jdbc.driver.OraclePreparedStatement.getParameterMetaData(OraclePreparedStatement.java:12861)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getParameterMetaData(OraclePreparedStatementWrapper.java:1551)
at org.apache.commons.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221)
at org.apache.commons.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221)
at org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:341)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:386)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:329)
.m2\repository\junit\junit\4.12\junit-4.12.jar
.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar
.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar
.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar
.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
.m2\repository\org\apache\logging\log4j\log4j-api\2.8\log4j-api-2.8.jar
.m2\repository\org\apache\logging\log4j\log4j-core\2.8\log4j-core-2.8.jar
.m2\repository\org\apache\logging\log4j\log4j-jcl\2.8\log4j-jcl-2.8.jar
.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar
.m2\repository\commons-dbcp\commons-dbcp\1.4\commons-dbcp-1.4.jar
.m2\repository\commons-pool\commons-pool\1.5.4\commons-pool-1.5.4.jar
.m2\repository\com\oracle\ojdbc6\12.1.0.2.0\ojdbc6-12.1.0.2.0.jar
.m2\repository\com\oracle\oraclepki\12.1.0.2.0\oraclepki-12.1.0.2.0.jar
.m2\repository\com\oracle\osdt_cert\12.1.0.2.0\osdt_cert-12.1.0.2.0.jar
.m2\repository\com\oracle\osdt_core\12.1.0.2.0\osdt_core-12.1.0.2.0.jar
.m2\repository\commons-dbutils\commons-dbutils\1.7\commons-dbutils-1.7.jar