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

Wrong ResultSetMetaData after ResultSet#insertRow

    XMLWordPrintable

    Details

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP prof. SP-2

      A DESCRIPTION OF THE PROBLEM :
      After executing ResultSet#updateString and ResultSet#insertRow, ResultSet#getMetaData().getColumnType(int) returns - 2 for a VARCHAR column.

      Database here is Microsoft Access, but in this case, I think type of DB
      is not important. At the state of my analysis, reason of this and some
      others of the listed bugs is the misuse of the fields 'len' and 'type'
      in class sun.jdbc.odbc.JdbcOdbcBoundCol.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Open ResultSet
      - Verify ResultSet's MetaData before
      - Insert a String in a column
      - Get ResultSet's MetaData


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Types.VARCHAR

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * JdbcOdbcResultSetTest.java
       * JUnit based test
       *
       * Created on 11. Juni 2006, 02:33
       */

      package sun.jdbc.odbc;

      import junit.framework.*;
      import java.sql.*;

      /**
       *
       * @author Ulf Zibis
       */
      public class JdbcOdbcResultSetTest extends TestCase {
        
        private final static String URL = "jdbc:odbc:TestData";
        private final static String TABLE = "Test1";
        private final static String STRING1 = "string1";
        private final static String INT1 = "int1";
        private final static String STRING32CHARS = "Here are only 16 + 16 more chars";
        
        private Connection con = null;
        
        public JdbcOdbcResultSetTest(String testName) {
          super(testName);
          try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection( URL);
          } catch (SQLException se) {
            System.out.println( se+", Error: "+se.getErrorCode()+", SQLState: "+se.getSQLState());
            se.printStackTrace();
          } catch (Throwable t) {
            t.printStackTrace();
          }
        }
        protected void finalize() {
          try { if (con != null) con.close(); }
          catch (Throwable t) { t.printStackTrace(); }
        }
        
        protected void setUp() throws Exception {

          System.out.println();
          Statement stmt = con.createStatement();
          try {
            ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM "+TABLE);
            rs.next();
            System.out.println( TABLE+" had "+rs.getInt( 1)+" record(s).");
            stmt.executeUpdate("DROP TABLE "+TABLE);
          }
          catch (SQLException se) {
            if (se.getErrorCode() == -1305)
              System.out.println( TABLE+" was not existent.");
            else throw se;
          }
          stmt.executeUpdate("CREATE TABLE "+TABLE+"( id COUNTER PRIMARY KEY, "
                                                     +STRING1+" VARCHAR(100), "
                                                     +INT1+" INT)");
          System.out.println("New empty table "+TABLE+" created !");
          stmt.close();
        }
        protected void tearDown() throws Exception {
        }
        
        public void testgetMetaData() throws Exception {
          System.out.println("testInsertRow()");
          try {
            Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            JdbcOdbcResultSet rs = (JdbcOdbcResultSet)stmt.executeQuery("SELECT * FROM "+TABLE+" WHERE id=0");
            rs.next(); // avoid other bug
            int result = rs.getMetaData().getColumnType( rs.findColumn( STRING1));
            assertEquals("rs.getMetaData().getColumnType( STRING1) before insert: ",
                         Types.VARCHAR, result);
            rs.moveToInsertRow();
            rs.updateString( STRING1, STRING32CHARS);
            rs.insertRow();
            rs.last();

            result = rs.getMetaData().getColumnType( rs.findColumn( STRING1));
            assertEquals("rs.getMetaData().getColumnType( STRING1) after insert: ",
                         Types.VARCHAR, result);
            stmt.close();
          } catch (SQLException se) {
            throw new Exception( se+", Error: "+se.getErrorCode()+", SQLState: "+se.getSQLState());
          }
        }
        

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: