我正在使用带有 ojdbc6.jar 的 Oracle Database 11.2.0.4,并且我正在使用带有 JDK 7 的 apache commons dbutils v1.7。所以我在这个函数中使用了 QueryRunner 及其方法
private <T> List<T> executeQueryAndReturnBeanList(String query, Class<T> className, Object... param) throws SQLException {
Connection connection = getDBConnectionInstance();
DbUtils.loadDriver("oracle.jdbc.driver.OracleDriver");
ResultSetHandler<List<T>> beanListHandler = new BeanListHandler<>(className,new BasicRowProcessor(new GenerousBeanProcessor()));
QueryRunner runner = new QueryRunner();
List<T> list = runner.query(connection, query, beanListHandler, param);
return list;
}
并且没有绑定参数的选择查询一切正常
SELECT * FROM PEOPLE WHERE GRUPPO = 1 AND LANG = 'en_US'
但是当我执行这个查询时
String query = "SELECT * FROM PEOPLE WHERE GRUPPO = ? AND LANG = ?";
它给了我这个 SQL 异常
java.sql.SQLException: ORA-00942: table or view does not exist
Query: SELECT * FROM PEOPLE WHERE GRUPPO = ? AND LANG = ? Parameters: [1, en_US]
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:252)
at mypackage.executeQueryAndReturnBeanList(JDBCFunctions.java:199)
我真的不知道为什么。我尝试使用:P1, :P2或:1, :2而不是? 绑定参数,但没有任何反应。有任何想法吗?