DbUtils1.6+Druid1.0.20绑定变量查询oracle时报java.sql.SQLException: ORA-00942: 表或视图不存在

庆庆他爸 发布于 2016/06/17 14:33
阅读 725
收藏 1

@wenshao 你好,想跟你请教个问题:DbUtils1.6+Druid1.0.20绑定变量查询oracle时报java.sql.SQLException: ORA-00942: 表或视图不存在

部分代码如下


String sql = "select * from  user_tables where status=? and pct_free>=?  and rownum<10";
sql="select * from nm_dm_obj_def t where prvcode=? and os_db_type=? and oper_time>to_date(?,'yyyymm')";
//List<Map<String, String>> result = db.queryForMapStrList(sql, new Object[]{"VALID",10});
List<Map<String, String>> result = db.queryForMapStrList(sql, new Object[]{"100","aix","201501"});


for (Map map : result) {
    System.out.println(map)
}

nm_dm_obj_def是业务表,user_tables是oracle系统表

使用绑定变量查询user_tables时是正常的。查询业务表时报如下错误:

java.sql.SQLException: ORA-00942: 表或视图不存在
 Query: select * from nmcuser.nm_dm_obj_def t where prvcode=? and os_db_type=? and oper_time>to_date(?,'yyyymm') Parameters: [100, aix, 201501]
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:289)
at com.asiainfo.util.DBBase.queryForMapStrList(DBBase.java:367)
at com.asiainfo.main.dbTest.main(dbTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Exception in thread "main" java.lang.NullPointerException
at com.asiainfo.main.dbTest.main(dbTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)



刚才又试了一下,把sql改为

select * from nmcuser.nm_dm_obj_def t where prvcode= ? and os_db_type=? and oper_time> to_date(?,'yyyymm')

就可以正常运行了。唯一的区别是oper_time>与to_date之间增加了一个空格

加载中
0
庆庆他爸
问题已经解决,是oracle jdbc驱动包的问题
返回顶部
顶部