简体   繁体   English

JDBC Oracle结果集空指针异常

[英]JDBC Oracle Result set Null Pointer Exception

I have a multi threaded program which connects to a oracle database. 我有一个连接到oracle数据库的多线程程序。

The first thread executes a "big" query and loads the objects in to a LinkedBlockingQueue. 第一个线程执行“大”查询,并将对象加载到LinkedBlockingQueue中。 There are around 200,000 objects. 大约有200,000个对象。

The second thread polls this list, and for each object, it runs 14 other queries, updating the object parameters. 第二个线程轮询此列表,并针对每个对象运行其他14个查询,从而更新对象参数。 Then I connect to another database, one final time, get corresponding object for this current object, create a hybrid object containing these two objects and sends it to third thread. 然后,我最后一次连接到另一个数据库,获取该当前对象的对应对象,创建一个包含这两个对象的混合对象,并将其发送到第三个线程。

I am using a single statement and multiple result sets for each one of these 14 queries. 我对这14个查询中的每一个使用单个语句和多个结果集。

    stat=predefinedobject.getConnection().createStatement();  
    ResultSet rs = null;
    ResultSet rs1 = null;
    ResultSet rs2 = null;
    ResultSet rs3 = null;
          .
          .
    rs=stat.executeQuery(Query1);
    while(rs.next()) {
        object1.setParameter1(rs.getString(5));
    }
    SqlUtils.closeResultSet(rs);

    rs1=stat.executeQuery(Query2);
    while(rs1.next()) {
        object1.setParameter2(rs1.getString(5));
    }
    SqlUtils.closeResultSet(rs1);
           .
           .
           .
    SqlUtils.closeResultSet(rs14);
    SqlUtils.closeResultSet(stat);

I am getting the null pointer exception after some time. 一段时间后,我得到了空指针异常。

java.lang.NullPointerException
at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java:876)
at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:825)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1049)
at oracle.jdbc.driver.T4CStatement.executeMaybeDescribe(T4CStatement.java:845)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1154)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1313)

Double check your sql query strings , it seems you concatenate the query but missing some space in it. 仔细检查您的sql查询字符串,看来您是将查询连接起来但缺少一些空间。

For example; 例如;

String sql="select"+MYCOULUM+" form MYTABLE"

will produce the following string 将产生以下字符串

selectMYCOULUM form MYTABLE

and executing such query will result this error for oracle jdbc driver 和执行这样的查询将导致此错误的Oracle jdbc驱动程序

The javadoc says - By default, only one ResultSet object per Statement object can be open at the same time. javadoc说-默认情况下,每个Statement对象只能同时打开一个ResultSet对象。 Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. 因此,如果一个ResultSet对象的读取与另一个对象的读取是交错的,则每个都必须由不同的Statement对象生成。 All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists. 如果存在打开的语句,Statement接口中的所有执行方法都会隐式关闭该语句的当前ResultSet对象。

So may be try to create a new Statement object each time you want to query the database 因此,可能需要在每次要查询数据库时尝试创建一个新的Statement对象

In my case, I've used upper case CALL instead of lower case call to call stored proc. 就我而言,我使用大写CALL而不是小写call来调用存储的proc。

For example, { ?= CALL proc_name(?) } is giving the same error. 例如, { ?= CALL proc_name(?) }给出了相同的错误。 Once I change to { ?= call proc_name(?) } it is working 一旦我更改为{ ?= call proc_name(?) }它就可以工作了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM