Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-424

JDBC connector 1.5.6+: preparedStatement + getGeneratedKeys() = faulty exception on _first_ resultset.next()

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.5.7
    • 1.5.8
    • Other

    Description

      {{ connection = dataSource.getConnection();
      statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
      <... >
      result = statement.executeUpdate();

      ResultSet rs = statement.getGeneratedKeys();
      }}

      rs.next() now throws java.sql.SQLException: Operation not permit on a closed resultSet.

      This should not happen on first call to rs.next().

      Bug introduced in 1.5.7, 1.5.6 behaves as it should with regards to this.

      Attachments

        Activity

          danielnilssonse Daniel Nilsson created issue -
          danielnilssonse Daniel Nilsson made changes -
          Field Original Value New Value
          Description {{ connection = dataSource.getConnection();
                      statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                      <... >
                      result = statement.executeUpdate();

                      ResultSet rs = statement.getGeneratedKeys();
          }}

          rs.next() now throws java.sql.SQLException: Operation not permit on a closed resultSet.

          This should not happen on first call to rs.next().

          Bug introduced in 1.5.7, 1.5.6 behaves as it should with regards to this.



          asdfdasf
          {{ connection = dataSource.getConnection();
                      statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                      <... >
                      result = statement.executeUpdate();

                      ResultSet rs = statement.getGeneratedKeys();
          }}

          rs.next() now throws java.sql.SQLException: Operation not permit on a closed resultSet.

          This should not happen on first call to rs.next().

          Bug introduced in 1.5.7, 1.5.6 behaves as it should with regards to this.
          diego dupin Diego Dupin added a comment -

          could you post full stracktrace ? I fail to reproduced these issue

          (try with this works well

          @Test
          public void testt()throws Exception {
           
              try (Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost/testj?user=root")) {
                  try (Statement statement = connection.createStatement()) {
                      statement.execute("DROP TABLE IF EXISTS tableTest");
                      statement.execute("CREATE TABLE tableTest(id int auto_increment primary key, data varchar(20)) ");
                  }
                  try (PreparedStatement prepStmt = sharedConnection.prepareStatement("INSERT INTO tableTest(data) values ('data')", Statement.RETURN_GENERATED_KEYS)) {
                      prepStmt.executeUpdate();
           
                      ResultSet rs = prepStmt.getGeneratedKeys();
                      rs.next();
                      Assert.assertEquals(1, rs.getInt(1));
                  }
              }
          }
          
          

          diego dupin Diego Dupin added a comment - could you post full stracktrace ? I fail to reproduced these issue (try with this works well @Test public void testt() throws Exception {   try (Connection connection = DriverManager.getConnection( "jdbc:mariadb://localhost/testj?user=root" )) { try (Statement statement = connection.createStatement()) { statement.execute( "DROP TABLE IF EXISTS tableTest" ); statement.execute( "CREATE TABLE tableTest(id int auto_increment primary key, data varchar(20)) " ); } try (PreparedStatement prepStmt = sharedConnection.prepareStatement( "INSERT INTO tableTest(data) values ('data')" , Statement.RETURN_GENERATED_KEYS)) { prepStmt.executeUpdate();   ResultSet rs = prepStmt.getGeneratedKeys(); rs.next(); Assert.assertEquals( 1 , rs.getInt( 1 )); } } }
          danielnilssonse Daniel Nilsson made changes -
          Summary JDBC connector 1.5.7 (not 1.5.6): preparedStatement + getGeneratedKeys() = faulty exception on _first_ resultset.next() JDBC connector 1.5.6+: preparedStatement + getGeneratedKeys() = faulty exception on _first_ resultset.next()
          danielnilssonse Daniel Nilsson added a comment - - edited

          Hi Diego, we're working on providing a good way to reproduce.

          I also edited the description of this issue - seems like the problem arrived with 1.5.6, not 1.5.7. 1.5.5 works as expected.

          The exception is thrown by the first line of MariaSelectResultSet next() method.

          danielnilssonse Daniel Nilsson added a comment - - edited Hi Diego, we're working on providing a good way to reproduce. I also edited the description of this issue - seems like the problem arrived with 1.5.6, not 1.5.7. 1.5.5 works as expected. The exception is thrown by the first line of MariaSelectResultSet next() method.

          I might add - we have an internal test that does reproduce this issue, just have to slim it down to something suitable for your GeneratedKeysTest.java.

          danielnilssonse Daniel Nilsson added a comment - I might add - we have an internal test that does reproduce this issue, just have to slim it down to something suitable for your GeneratedKeysTest.java.

          Use this code to reproduce the problem (in the GeneratedKeysTest.java test class context):

              /**
               * CONJ-424: Calling getGeneratedKeys() two times on the same connection, with different
               * PreparedStatement on a table that does not have an auto increament.
               */
              @Test
              public void testGeneratedKeysWithoutTableAutoIncrementCalledTwice() throws SQLException {
                  createTable("gen_key_test_resultset", "name VARCHAR(40) NOT NULL, xml MEDIUMTEXT");
                  String sql = "INSERT INTO gen_key_test_resultset (name, xml) VALUES (?, ?)";
                  PreparedStatement preparedStatement;
                  ResultSet generatedKeysResultSet;
                  for (int i = 0; i < 2; i++) {
                      preparedStatement = sharedConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                      preparedStatement.setString(1, "John");
                      preparedStatement.setString(2, "<xml/>");
                      preparedStatement.executeUpdate();
           
                      generatedKeysResultSet = preparedStatement.getGeneratedKeys();
                      if (generatedKeysResultSet.next()) {
                          Assert.fail("Should not get here!");
                      }
                      generatedKeysResultSet.close();
                      preparedStatement.close();
                  }
              }
          

          lennartschedin Lennart Schedin added a comment - Use this code to reproduce the problem (in the GeneratedKeysTest.java test class context): /** * CONJ-424: Calling getGeneratedKeys() two times on the same connection, with different * PreparedStatement on a table that does not have an auto increament. */ @Test public void testGeneratedKeysWithoutTableAutoIncrementCalledTwice() throws SQLException { createTable( "gen_key_test_resultset" , "name VARCHAR(40) NOT NULL, xml MEDIUMTEXT" ); String sql = "INSERT INTO gen_key_test_resultset (name, xml) VALUES (?, ?)" ; PreparedStatement preparedStatement; ResultSet generatedKeysResultSet; for ( int i = 0 ; i < 2 ; i++) { preparedStatement = sharedConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString( 1 , "John" ); preparedStatement.setString( 2 , "<xml/>" ); preparedStatement.executeUpdate();   generatedKeysResultSet = preparedStatement.getGeneratedKeys(); if (generatedKeysResultSet.next()) { Assert.fail( "Should not get here!" ); } generatedKeysResultSet.close(); preparedStatement.close(); } }
          diego dupin Diego Dupin made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.5.8 [ 22509 ]
          diego dupin Diego Dupin added a comment -

          correction in done in 1.5.8-SNAPSHOT, available using :

          <repositories>
              <repository>
                  <id>sonatype-nexus-snapshots</id>
                  <name>Sonatype Nexus Snapshots</name>
                  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
              </repository>
          </repositories>
           
          <dependencies>
              <dependency>
                  <groupId>org.mariadb.jdbc</groupId>
                  <artifactId>mariadb-java-client</artifactId>
                  <version>1.5.8-SNAPSHOT</version>
              </dependency>
          </dependencies>
          

          could you confirm it solve this issue ?

          diego dupin Diego Dupin added a comment - correction in done in 1.5.8-SNAPSHOT, available using : <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https: //oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories>   <dependencies> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version> 1.5 . 8 -SNAPSHOT</version> </dependency> </dependencies> could you confirm it solve this issue ?

          Thanks Diego!

          I've been busy trying to write a workaround here for another issue that we face - apparently you now by default enable STRICT_TRANS_TABLES with gives us some grief. A ticket is coming on that aswell

          I have to try and finish a workaround for that before I get to testing your fix. Not sure if I can manage before the weekend, sorry.

          danielnilssonse Daniel Nilsson added a comment - Thanks Diego! I've been busy trying to write a workaround here for another issue that we face - apparently you now by default enable STRICT_TRANS_TABLES with gives us some grief. A ticket is coming on that aswell I have to try and finish a workaround for that before I get to testing your fix. Not sure if I can manage before the weekend, sorry.
          diego dupin Diego Dupin added a comment - - edited

          danielnilssonse, JDBC required that when a data truncation occur an exception is thrown.
          That correspond to having STRICT_TRANS_TABLES set.

          So that's the default implementation, but can be disabled using jdbcCompliantTruncation=false in connection string. see more in docs

          diego dupin Diego Dupin added a comment - - edited danielnilssonse , JDBC required that when a data truncation occur an exception is thrown. That correspond to having STRICT_TRANS_TABLES set. So that's the default implementation, but can be disabled using jdbcCompliantTruncation=false in connection string. see more in docs
          diego dupin Diego Dupin made changes -
          Component/s Other [ 12201 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 79511 ] MariaDB v4 [ 134950 ]

          People

            diego dupin Diego Dupin
            danielnilssonse Daniel Nilsson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.