代码:
QueryRunner queryRunner = new QueryRunner();
connection = JdbcUtils.getConnection();
String sql = "SELECT id,name,address,phone FROM customer WHERE name LIKE ?";
List<Customer> list = queryRunner.query(connection,sql,new BeanListHandler<Customer>(Customer.class), "%j%");
for(Customer c: list){
System.out.println(c);
}
当我使用自己的DAO代码查询时,它没问题。但是使用queryRunner,会出现以下异常:
java.sql.SQLException: ORA-00904: "NAMEIKE": invalid identifier
Query: SELECT id,name,address,phone FROM customer WHERE name LIKE ? Parameters: [%j%]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:351)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:212)
at com.lteagle.mvcapp.test.Test.main(Test.java:19)
我不知道无效标识符“NAMEIKE”的来源。
答案 0 :(得分:0)
你可以尝试这个吗..什么是J,你传递给查询跑步者的查询方法的参数
QueryRunner queryRunner = new QueryRunner();
connection = JdbcUtils.getConnection();
String sql = "SELECT id,name,address,phone FROM customer WHERE name LIKE ?";
List<Customer> list = queryRunner.query(connection,sql,new BeanListHandler<Customer>(Customer.class), "%"+j+"%");
for(Customer c: list){
System.out.println(c);
}