【问题标题】:Getting an exception when query oracle with Dbutils使用 Dbutils 查询 oracle 时出现异常
【发布时间】:2017-03-23 02:00:50
【问题描述】:

代码:

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”来自哪里。

【问题讨论】:

    标签: java oracle apache-commons-dbutils


    【解决方案1】:

    你可以试试这个..什么是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);
    }
    

    【讨论】:

    • 我要模糊查询,'j'只是'name'中的一个字符。
    猜你喜欢
    • 2012-12-29
    • 2021-04-04
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 2015-12-18
    • 2018-04-30
    相关资源
    最近更新 更多