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

CachedRowSet.Impl.refreshRow doesn't work as expected

XMLWordPrintable

    • Fix Understood
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      refreshRow specification says that calling this method will update the current row with the value from the database but it doesn't necessarly do so.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached example

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the example should output :

      new value in the CachedRowSet *after* refreshRow: new value


      ACTUAL -
      while it output:

      new value in the CachedRowSet *after* refreshRow: the old value

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.sql.SQLException;

      import javax.sql.rowset.CachedRowSet;
      import javax.sql.rowset.JdbcRowSet;

      import com.sun.rowset.CachedRowSetImpl;
      import com.sun.rowset.JdbcRowSetImpl;

      /**
       * @author jolif
       *
       */
      public class RowSetPb3
      {
        final static String databaseURL = "jdbc:mysql:///test";
        final static String user = "";
        final static String passwd = "";
        final static String driverName = "com.mysql.jdbc.Driver";
        final static String TABLE_NAME = "activities";
           
        public RowSetPb3()
        {
        }

        // CJO 11/04
        public static void main(String[] arg)
          throws Exception
        {
          new RowSetPb3().test();
        }
        
        public void test() throws ClassNotFoundException, InstantiationException,
                                  IllegalAccessException, SQLException, InterruptedException
        {
          Class.forName(driverName);

          CachedRowSet rowSet = new CachedRowSetImpl();
          rowSet.setUrl(databaseURL);
          rowSet.setUsername(user);
          rowSet.setPassword(passwd);
          rowSet.setCommand("select * from " +TABLE_NAME);
          rowSet.execute();
          rowSet.next();

          JdbcRowSet jdbcRowSet = new JdbcRowSetImpl();
          jdbcRowSet.setUrl(databaseURL);
          jdbcRowSet.setUsername(user);
          jdbcRowSet.setPassword(passwd);
          jdbcRowSet.setCommand("select * from " +TABLE_NAME);
          jdbcRowSet.execute();
          jdbcRowSet.next();
          
          System.out.println("initial value in the CachedRowSet: "+rowSet.getObject(2));
          // modify a value in the dbase
          jdbcRowSet.updateObject(2, "new value");
          jdbcRowSet.updateRow();
          if (!jdbcRowSet.getAutoCommit())
            jdbcRowSet.commit();
          jdbcRowSet.close();
          // in the CachedRowSet call refreshRow to get the new value
          rowSet.refreshRow();
          // try to print the new value
          System.out.println("new value in the CachedRowSet *after* refreshRow: "+rowSet.getObject(2));
      }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: