public int insert(Order order)
      throws SQLException
  {
    PreparedStatement insert = null;
    int orderKey = -1;

    try
    {
      String method = new String("DBInterface.insert( Order )");
      FileLogger.log(FileLogger.HIGH, method + " - Entering...");

      int col = 0;
      int actionCode = getCodeKey("ORDER_ACTION", order._action);
      int statusCode = getCodeKey("PCO_AUTO_STATUS", order._status);
      int falloutTypeCode = getCodeKey("FALLOUT_TYPE", order._falloutType);
      orderKey = getSequenceNo("TC_ORDER_SEQ");
      int primaryClfiKey = lookupByValue("TC_CLFI", order._primaryClfi);
      FileLogger.log(FileLogger.HIGH,
                     "accessing fac_assembly: " + order._facAssembly);
      int facAssemblyKey = lookupByValue("TC_FAC_ASSEMBLY", order._facAssembly);
      FileLogger.log(FileLogger.HIGH,
                     "after accessing fac_assembly: " + order._facAssembly);
      int pcoClliKey = lookupByValue("TC_CLLI", order._pcoClli);
      String stmt = new String("INSERT INTO TC_ORDER (ORDER_KEY, ORDER_NUMBER, PCO_CLLI_KEY, PRIMARY_CLFI_KEY, ACTION_CD_KEY,
 DUE_DATE, ISSUE_DATE, CUT_CODE, PON, FAC_ASSEMBLY_KEY, ORDER_MSG_RAW, AUTO_STATUS_CD_KEY, START_DT, FALLOUT_TYPE_CD_KEY, FAL
LOUT_TO_OSDS_FG ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
      FileLogger.log(FileLogger.HIGH, stmt);
      insert = _conn.prepareStatement(stmt);
      insert.setInt(++col, orderKey);
      insert.setString(++col, order._orderNumber);
      insert.setInt(++col, pcoClliKey);
      insert.setInt(++col, primaryClfiKey);
      insert.setInt(++col, actionCode);
      insert.setTimestamp(++col, new java.sql.Timestamp(order._dueDate.getTime()));
      insert.setTimestamp(++col,
                          new java.sql.Timestamp(order._issueDate.getTime()));
      insert.setString(++col, order._cutCode);
      insert.setString(++col, order._PON);
      insert.setInt(++col, facAssemblyKey);
      InputStream is = new ByteArrayInputStream(order._xmlMsg.getBytes());
      StringReader reader = new StringReader(order._xmlMsg);
      insert.setCharacterStream(++col, reader, order._xmlMsg.length());
      insert.setInt(++col, statusCode);
      insert.setTimestamp(++col,
                          new java.sql.Timestamp(order._startDate.getTime()));
      insert.setInt(++col, falloutTypeCode);
      insert.setShort(++col, order._falloutToOsds);
      insert.executeUpdate();
      FileLogger.log(FileLogger.HIGH, method + "Returning key: " + orderKey);
      return orderKey;
    }
    catch (SQLException sqle)
    {
      FileLogger.log(FileLogger.ERROR,
                     "DBInterface.insert(Order) -  caught and will throw " +
                     sqle.toString() +
                     "; error code: " + sqle.getErrorCode() +
                     "; sql state: " + sqle.getSQLState() +
                     "; next exception: " + sqle.getNextException());
      FileLogger.debug(order);
      throw sqle;
    }
    finally
    {
      FileLogger.log(FileLogger.HIGH,
                     "DBInterface.insert(Order) - cleaning up...");
      insert.close();
    }

  }

I get an error at the above finally block for nullpoint exception at inser.close() line. Please help

Ata guess you have an exception thrown before line 28, so insert (the variable, not the method) is still null when the finally blcok is executes after the catch?

Please eloborate on what i should do

In your finally block you don't want to execute the close() if insert has not been initialised, so maybe something like this?

if (insert != null) insert.close();

java.lang.NullPointerException
        at com.att.pco.db.DBInterface.insert(DBInterface.java:1766)
        at com.att.pco.wfm.ImportControllerListener.handleNewOrderEvent(ImportControllerListener.java:420)
        at com.att.pco.wfm.ImportControllerListener.handleEvent(ImportControllerListener.java:193)
        at com.att.pco.wfm.ImportControllerListener.processMessage(ImportControllerListener.java:165)
        at com.att.infra.EventNotifier.processMessages(EventNotifier.java:101)
        at com.att.infra.EventNotifier.run(EventNotifier.java:234)



    I am getting this error :(

You need to show us which line is line 1766 in com.att.pco.db.DBInterface

It is that finally block inser.close() line :(

Do you want that ImportControllerListener.java also?

Did you change it as I suggested?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.