简体   繁体   中英

java.lang.NullPointerException while getting a cursor in JDBC

I'm getting java.lang.NullPointerException while accesing a cursor that a procedure returns as an out parameter.

Here are the details:

    CallableStatement pstmt = conn.prepareCall("{call PKP_UTIL.GET_VALUE(?,?,?)}");
    pstmt.setObject(1, parameter1);
    pstmt.setObject(2, parameter2);
    pstmt.registerOutParameter(3, OracleTypes.CURSOR);

    pstmt.executeUpdate(); //in this line all goes wrong

    ResultSet rs = (ResultSet)pstmt.getObject(3);

    while (rs.next()) {
         System.out.println(rs.getString(1) + "\t" + rs.getFloat(2) + "\t" + rs.getDate(3).toString());

    }

The details of the application are: - Restful WS on Tomcat 6 - Oracle 11g ((11.2.0.2.0) - JDK 1.7 - JDBC Thin driver

If I try this same code on a desktop application, it works like a charm.

pstmt.executeUpdate(); //in this line all goes wrong

Not surprising. It should be execute(). The Javadoc for executeUpdate() specifically says the statement must be a 'SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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