cool18TH 2017-04-28 06:45 采纳率: 0%
浏览 1595
已结题

急!queryrunner查询时报“表或视图不存在”

//DAO层
public List getForList(String sql, Object... args) {
Connection connection = null;
System.out.println(args);
try {
connection = JdbcUtils.getConnection();
return queryRunner.query(connection, sql, new BeanListHandler(clazz), args);
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtils.releaseConnection(connection);
}
return null;
}

//接口实现
public class BookListDaoImpl extends DAO<Book> implements BookListDao{
public List<Book> getByUserIdWithOrdered(String id) {

// String sql =
// "select distinct TBkInfo.*,courseInfo.name coursename from userInfo,courseInfo,TBkInfo " +
// "where userInfo.id = ? and (userInfo.major = courseInfo.major or courseInfo.major is null) " +
// "and courseInfo.TBkId = TBkinfo.Id "
// + "and TBkinfo.Id in ( select orderlist.TBkId from orderlist where orderlist.userid = ? )";

    String sql = "select distinct TBkInfo.*,courseInfo.name coursename  from userInfo,courseInfo,TBkInfo,orderlist ol " + 
                            "where userInfo.id = ? and  ol.userid = ? and userInfo.major = courseInfo.major " +
                            "and courseInfo.TBkId = TBkinfo.Id and  TBkinfo.Id = ol.TBkId";
    return getForList(sql,id, id);
}
}

异常:
java.sql.SQLException: ORA-00942: 表或视图不存在

Query: select distinct TBkInfo.*,courseInfo.name coursename from userInfo,courseInfo,TBkInfo,orderlist ol where userInfo.id = ? and ol.userid = ? and userInfo.major = courseInfo.major and courseInfo.TBkId = TBkinfo.Id and TBkinfo.Id = ol.TBkId Parameters: [2013215087, 2013215087]
at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:542)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:399)
at com.TBO.DAO.DAO.getForList(DAO.java:77)
at com.TBO.DAOImpl.BookListDaoImpl.getByUserIdWithOrdered(BookListDaoImpl.java:20)
at com.TBO.test.test.test(test.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

说明:select语句中的表都存在,sql语句在PLsql中能够得到正确结果。现将其写到java中,并使用通配符,出下一下情况:
情况一:
String sql =
            "select distinct TBkInfo.*,courseInfo.name coursename  from userInfo,courseInfo,TBkInfo " +
            "where userInfo.id = ? and (userInfo.major = courseInfo.major or courseInfo.major is null) " +
            "and courseInfo.TBkId = TBkinfo.Id "
            + "and  TBkinfo.Id in ( select orderlist.TBkId from orderlist where orderlist.userid = ? )";
            return getForList(sql,id, id);
            结果:报上面提到的异常


情况二:将sql语句写实
String sql =
            "select distinct TBkInfo.*,courseInfo.name coursename  from userInfo,courseInfo,TBkInfo " +
            "where userInfo.id = 2013215087 and (userInfo.major = courseInfo.major or courseInfo.major is null) " +
            "and courseInfo.TBkId = TBkinfo.Id "
            + "and  TBkinfo.Id in ( select orderlist.TBkId from orderlist where orderlist.userid = 2013215087)";
            return getForList(sql);
            结果:可得到正确结果

情况三:
public void test() {
DAO < Order > dao = new DAO < Order>();
dao.getForList("select * from orderlist ");
}
说明:Order是个bean,成员变量与数据库字段对应
结果:
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 10, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> mvcapp, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1br3s3l9n1dqtu2imjlrpx|427800ef, idleConnectionTestPeriod -> 0, initialPoolSize -> 20, jdbcUrl -> jdbc:oracle:thin:@127.0.0.1:1521:TBO, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 60, maxStatements -> 40, maxStatementsPerConnection -> 10, minPoolSize -> 20, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
java.lang.NullPointerException
at sun.reflect.misc.ReflectUtil.checkPackageAccess(ReflectUtil.java:164)
at sun.reflect.misc.ReflectUtil.isPackageAccessible(ReflectUtil.java:195)
at java.beans.Introspector.getBeanInfo(Introspector.java:154)
at org.apache.commons.dbutils.BeanProcessor.propertyDescriptors(BeanProcessor.java:358)
at org.apache.commons.dbutils.BeanProcessor.toBeanList(BeanProcessor.java:168)
at org.apache.commons.dbutils.BasicRowProcessor.toBeanList(BasicRowProcessor.java:134)

情况四:
public List<Book> getByUserIdWithOrdered(String id) {
String sql =
        "select distinct TBkInfo.*,courseInfo.name coursename  from userInfo,courseInfo,TBkInfo " +
        "where userInfo.id = ? and (userInfo.major = courseInfo.major or courseInfo.major is null) " +
        "and courseInfo.TBkId = TBkinfo.Id ";
    return getForList(sql,id);
}
结果:得到正确结果


再次说明,以上的sql语句在PLsql中都能得到正确结果,getForList在多个模块中用到,也存在通配符,但只在当前情况下抛异常。数据库用户具有DAB权限
  • 写回答

1条回答 默认 最新

  • devmiao 2017-04-28 07:20
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?