Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4402655

NullPointerException in ResultSet.updateInt

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • x86
    • windows_nt



      Name: yyT116575 Date: 01/08/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      The result of running the attached code is

      java.lang.NullPointerException
      at sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues
      (JdbcOdbcBoundCol.java:240)
      at sun.jdbc.odbc.JdbcOdbcResultSet.updateInt
      (JdbcOdbcResultSet.java:3153)
      at test.jdbc.TestResultInsert.fillTable(TestResultInsert.java:45)
      at test.jdbc.TestResultInsert.main(TestResultInsert.java:15)

      I am using MS SQLServer 7, with the standard ODBC driver. The application
      requires a single argument which is the appropriate url for a database
      (jdbc:odbc:MyData). It will create a suitable table and try to fill it with
      data using an updateable result set.

      package test.jdbc;

      import java.sql.*;

      class TestResultInsert
      {
        public static void main(String[] args)
        {
          String driver = System.getProperty("driver", "sun.jdbc.odbc.JdbcOdbcDriver");
          try
          {
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(args[0]);
            createTable(conn);
            fillTable(conn);
            readTable(conn);
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
          }
        }

        private static void createTable(Connection conn) throws SQLException
        {
          Statement s = conn.createStatement();
          try
          {
            s.executeUpdate("drop table BatchTable");
          }
          catch (SQLException ex)
          {
          }
          s.executeUpdate("create table BatchTable (row int, rv int)");
          s.close();
        }

        private static void fillTable(Connection conn) throws SQLException
        {
          Statement s = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
          ResultSet results = s.executeQuery("select row, rv from BatchTable");
          for (int i=1; i<=50; i++)
          {
            results.moveToInsertRow();
            results.updateInt(1, i);
            results.updateInt(2, -i);
            results.insertRow();
          }
          results.close();
          s.close();
        }

        private static void readTable(Connection conn) throws SQLException
        {
          Statement s = conn.createStatement();
          ResultSet results = s.executeQuery("select row,rv from BatchTable");
          int n=0;
          while (results.next())
          {
            System.out.print(results.getInt(1));
            System.out.print(" ");
            System.out.println(results.getInt(2));
            n++;
          }
          System.out.println(n+" Rows");
          results.close();
          s.close();
        }
      }
      (Review ID: 114717)
      ======================================================================

            jbrucesunw Jonathan Bruce (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: