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

updateXXX() do not work with a empty ResultSet

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • rc1
    • x86
    • windows_nt



      Name: bsC130419 Date: 06/15/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      The methods updateXXX never works with a empty ResulSet. We have test it with
      different databases (ODBC drivers).

      java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues (JdbcOdbcBoundCol.java:240)
        at sun.jdbc.odbc.JdbcOdbcResultSet.updateInt (JdbcOdbcResultSet.java:3166)
        at sun.jdbc.odbc.JdbcOdbcResultSet.updateInt (JdbcOdbcResultSet.java:3831)


      package test.jdbc;
      import java.sql.*;
      class TestResultInsert{

        public static void main(String[] args) {
          try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection("AnyDSN);
            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: 126655)
      ======================================================================

            jbrucesunw Jonathan Bruce (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: