Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    1

    Unanswered: got NullPointerException using executeQuery() !! Puzzled

    Hi

    I'm getting an unexpected NullPointerException thrown at the "second" call to executeQuery(). Looks like the PreparedStatement st is in an unstable state after the first pass thru the for loop. The ResultSet st is not null at this stage.
    The error is thrown inside executeQuery().
    My temporary solution is to put the line "st = con.prepareStatement(sql);" inside the loop, where it doesn't belong.
    I tried to call st.clearParameters() before every pass but that obviously doesn't work.

    Synchronization issue? bug?

    I'd appreciate any assistance.

    Thanks


    ## CODE

    String sql = "SELECT ORDER_ID, CREATION_DATE FROM LOG_ORDER WHERE ORDER_ID = ?";
    Connection con = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    int ordersFound = 0;
    int ordersNotFound = 0;

    try {
    con = getConnection();
    st = con.prepareStatement(sql);

    for (Iterator i = validPurchases.iterator(); i.hasNext() {
    ValidPurchase validPurchase = (ValidPurchase) i.next();
    int storePurchaseId = validPurchase.getStorePurchaseId();
    st.setInt(1, storePurchaseId);
    rs = st.executeQuery(); // line 57: NULL exception inside executeQuery()

    if (rs.next()) {
    logger.debug("ORDER [" + rs.getString("ORDER_ID") + "] [" + rs.getString("CREATION_DATE") + "]");
    ordersFound++;
    } else {
    logger.debug("NO Order match for [" + storePurchaseId + "] created on [" + validPurchase.getCreationDate() + "]");
    ordersNotFound++;
    }
    }
    } catch (SQLException e) {
    logger.error(e.getMessage());
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } finally {
    try {
    if (rs != null) {
    rs.close();
    }
    if (st != null) {
    st.close();
    }
    if (con != null) {
    con.close();
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }

    logger.info("SUMMARY: [" + ordersFound + " ] orders found");
    logger.info("SUMMARY: [" + ordersNotFound + " ] orders not found");
    }



    ## LOG + EXCEPTION

    2003-12-30 11:40:46,859 DEBUG [InformixJDBCTest] ORDER [10141730] [2003-12-09 08:26:15.0]
    2003-12-30 11:40:46,890 ERROR [InformixJDBCTest] System or internal error java.lang.NullPointerException
    java.sql.SQLException: System or internal error java.lang.NullPointerException
    at com.informix.util.IfxErrMsg.getSQLException(IfxErr Msg.java:423)
    at com.informix.jdbc.IfxSqli.executeStatementQuery(If xSqli.java:1364)
    at com.informix.jdbc.IfxSqli.executeStatementQuery(If xSqli.java:1283)
    at com.informix.jdbc.IfxResultSet.executeQuery(IfxRes ultSet.java:219)
    at com.informix.jdbc.IfxStatement.executeQueryImpl(If xStatement.java:815)
    at com.informix.jdbc.IfxPreparedStatement.executeQuer y(IfxPreparedStatement.java:244)
    at com.personal.database.InformixJDBCTest.reconcile(I nformixJDBCTest.java:57)

  2. #2
    Join Date
    Aug 2003
    Posts
    40
    I would not implement the SQL the way you have. I would make a
    stand-alone class that processes one SQL statement at a time and
    returns the return set.

    So, for the class you have shown, as it iterates thru the "validPurchases"
    to optain a different key value (and, consequently, a new SQL
    statement with return set values), call a modular SQL class and place
    the results in an object (such as an array/vector/hash table) for
    processing once all "valid purchases" have been examined.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •