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

@Query parameter parsing and DataSetItr is broken in JDBC 4

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • generic, x86
    • generic, windows_xp

      ========================================================================================
      JDK : java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b98)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b98, mixed mode)
      DB : JavaDB
      Driver : JavaDB
      Platform[s] : All
      ========================================================================================

      First issue : No check whether ?<number> is a literal. All ?<number> are considered as parameters and results in this issue.

      Second issue : The second issue is due to hashCode implementation in AbstractList. This can be easily fixed by overriding method equals and hashCode in DataSetImpl.

      Third Issue: ?1 and " as delimiter. For this we need better understanding of delimiter cases. I need to work more on this.

      EXCEPTION:
      ----------

      java.sql.SQLRuntimeException: Cannot retrieve query results
          at com.sun.sql.QueryObject$1.run(QueryObject.java:231)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:224)
          at $Proxy0.test1(Unknown Source)
          at EODQuestion.main(EODQuestion.java:56)
      Caused by: java.sql.SQLException: Number of arguments and parameters does not match
          at com.sun.sql.QueryObject.setArgsToSet(QueryObject.java:566)
          at com.sun.sql.QueryObject.getQueryImpl(QueryObject.java:702)
          at com.sun.sql.QueryObject.access$000(QueryObject.java:26)
          at com.sun.sql.QueryObject$1.run(QueryObject.java:229)
          ... 4 more
      ********** Test 1 FAILED
      ********** Test 2 ok
      java.sql.SQLRuntimeException: Cannot store DataSet instance to WeakHashMap
          at com.sun.sql.QueryObject.registerDataSet(QueryObject.java:1306)
          at com.sun.sql.QueryObject.getQueryImpl(QueryObject.java:767)
          at com.sun.sql.QueryObject.access$000(QueryObject.java:26)
          at com.sun.sql.QueryObject$1.run(QueryObject.java:229)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:224)
          at $Proxy0.test3(Unknown Source)
          at EODQuestion.main(EODQuestion.java:74)
      Caused by: java.lang.NullPointerException
          at com.sun.sql.DataSetImpl$DataSetItr.<init>(DataSetImpl.java:1759)
          at com.sun.sql.DataSetImpl$DataSetListIterator.<init>(DataSetImpl.java:1846)
          at com.sun.sql.DataSetImpl.listIterator(DataSetImpl.java:1628)
          at java.util.AbstractList.equals(AbstractList.java:503)
          at java.util.WeakHashMap.eq(WeakHashMap.java:259)
          at java.util.WeakHashMap.put(WeakHashMap.java:406)
          at com.sun.sql.QueryObject.registerDataSet(QueryObject.java:1304)
          ... 7 more
      ********** Test 3 FAILED
      java.sql.SQLRuntimeException: Cannot run update query
          at com.sun.sql.QueryObject$2.run(QueryObject.java:252)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:245)
          at $Proxy0.test4a(Unknown Source)
          at EODQuestion.main(EODQuestion.java:83)
      Caused by: java.sql.SQLException: No input parameters.
          at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
          at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement.getTypes(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement.getParameterJDBCType(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setObject(Unknown Source)
          at com.sun.sql.QueryObject.setParameterValue(QueryObject.java:528)
          at com.sun.sql.QueryObject.getUpdateImpl(QueryObject.java:466)
          at com.sun.sql.QueryObject.access$100(QueryObject.java:26)
          at com.sun.sql.QueryObject$2.run(QueryObject.java:250)
          ... 4 more
      Caused by: java.sql.SQLException: No input parameters.
          ... 19 more
      ********** Test 4a FAILED
      java.sql.SQLRuntimeException: Cannot retrieve query results
          at com.sun.sql.QueryObject$1.run(QueryObject.java:231)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:224)
          at $Proxy0.test4b(Unknown Source)
          at EODQuestion.main(EODQuestion.java:91)
      Caused by: java.sql.SQLSyntaxErrorException: Table/View 'weirdTable? ' does not exist.
          at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
          at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
          at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
          at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
          at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
          at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
          at com.sun.sql.QueryObject.getQueryImpl(QueryObject.java:708)
          at com.sun.sql.QueryObject.access$000(QueryObject.java:26)
          at com.sun.sql.QueryObject$1.run(QueryObject.java:229)
          ... 4 more
      Caused by: java.sql.SQLException: Table/View 'weirdTable? ' does not exist.
          ... 22 more
      ********** Test 4b FAILED
      java.sql.SQLRuntimeException: Cannot run update query
          at com.sun.sql.QueryObject$2.run(QueryObject.java:252)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:245)
          at $Proxy0.test5a(Unknown Source)
          at EODQuestion.main(EODQuestion.java:100)
      Caused by: java.sql.SQLException: Number of arguments and parameters does not match
          at com.sun.sql.QueryObject.setArgsToSet(QueryObject.java:566)
          at com.sun.sql.QueryObject.getUpdateImpl(QueryObject.java:460)
          at com.sun.sql.QueryObject.access$100(QueryObject.java:26)
          at com.sun.sql.QueryObject$2.run(QueryObject.java:250)
          ... 4 more
      ********** Test 5a FAILED
      java.sql.SQLRuntimeException: Cannot retrieve query results
          at com.sun.sql.QueryObject$1.run(QueryObject.java:231)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.sql.QueryObject.invoke(QueryObject.java:224)
          at $Proxy0.test5b(Unknown Source)
          at EODQuestion.main(EODQuestion.java:108)
      Caused by: java.sql.SQLException: Number of arguments and parameters does not match
          at com.sun.sql.QueryObject.setArgsToSet(QueryObject.java:566)
          at com.sun.sql.QueryObject.getQueryImpl(QueryObject.java:702)
          at com.sun.sql.QueryObject.access$000(QueryObject.java:26)
          at com.sun.sql.QueryObject$1.run(QueryObject.java:229)
          ... 4 more
      ********** Test 5b FAILED

      SOURCE:
      -------
      import java.sql.*;

      public class EODQuestion
      {
         static public class Row {
             String string;
         }
                interface RowQueryObject extends BaseQuery {
                    @java.sql.Update(sql="create table mytable (string varchar(255))")
                 int createTable();
                    // ?1 in literal
             @Select(sql="select * from mytable where string = '?1'")
                 DataSet<Row> test1();

             // One arg referenced twice
             @Select(sql="select * from mytable where string = ?1 and string < ?1")
                 DataSet<Row> test2(String a);
             // Two args, but only one referenced
             @Select(sql="select * from mytable where string = ?1")
                 DataSet<Row> test3(String a, String b);
             // Identifiers with ?1 and " as delimiters (legal SQL)
             @java.sql.Update(sql="create table\"weirdTable?1\"(\"weirdColumn?1\"varchar(255))")
                 int test4a(String a);

             @Select(sql="select\"weirdColumn?1\"from\"weirdTable?1\"")
                 DataSet<Row> test4b(String a);
             // Identifiers with ?1 and " as delimiters (legal SQL)
             @java.sql.Update(sql="create table\"weirdTable?1\"(\"weirdColumn?1\"varchar(255))")
                 int test5a();

             @Select(sql="select\"weirdColumn?1\"from\"weirdTable?1\"")
                 DataSet<Row> test5b();
         }
                  static public void main(String []args) throws Exception
         {
          String driver = "org.apache.derby.jdbc.EmbeddedDriver";
          String url = "jdbc:derby:/export/home/tmp/DB/eod;create=true";
                    Connection conn = DriverManager.getConnection(url);
                    RowQueryObject pqo = conn.createQueryObject(RowQueryObject.class);
             pqo.createTable();
                    try {
                 DataSet<Row> ds = pqo.test1();
                 ds.close();
                 System.out.println("********** Test 1 ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 1 FAILED");
             }

             try {
                 DataSet<Row> ds = pqo.test2("x");
                 ds.close();
                 System.out.println("********** Test 2 ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 2 FAILED");
             }

             try {
                 DataSet<Row> ds = pqo.test3("x","y");
                 ds.close();
                 System.out.println("********** Test 3 ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 3 FAILED");
             }

             try {
                 pqo.test4a("x");
                 System.out.println("********** Test 4a ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 4a FAILED");
             }

             try {
                 DataSet<Row> ds = pqo.test4b("x");
                 ds.close();
                 System.out.println("********** Test 4b ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 4b FAILED");
             }

             try {
                 pqo.test5a();
                 System.out.println("********** Test 5a ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 5a FAILED");
             }

             try {
                 DataSet<Row> ds = pqo.test5b();
                 ds.close();
                 System.out.println("********** Test 5b ok");
             } catch (Exception e) {
                 e.printStackTrace();
                 System.out.println("********** Test 5b FAILED");
             }

             pqo.close();

         }
      }

            ssharmasunw Sushmita Sharma (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: