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

Inconsistency in Handling PreparedStatement.executeQuery() between MariaDB and MySQL Connectors

    XMLWordPrintable

Details

    Description

      Using the MariaDB JDBC connector, the executeQuery() method on a PreparedStatement object does not throw an exception when used for an insert SQL statement.
      However, when the same operation is performed using the MySQL JDBC connector, it throws a java.sql.SQLException stating that Statement.executeQuery() cannot issue statements that do not produce result sets.
      The different behavior in handling PreparedStatement.executeQuery() will cause potential compatibility issues. For example:

      @Test
      public void test() throws SQLException {
          Connection con;
          Statement stmt;
          ResultSet rs;
          con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test42?user=user&password=password");
          stmt = con.createStatement(1004, 1008, 2);
          stmt.execute("CREATE TABLE table42_0(id INT PRIMARY KEY,value VARCHAR(100));");
          stmt.close();
          PreparedStatement pstmt = con.prepareStatement("INSERT INTO table42_0 VALUES(?, ?);");
          pstmt.setObject(1, "1868598290");
          pstmt.setObject(2, "'F^uNhSH.Cd;pH22.(xcX$Lr'");
          pstmt.addBatch();
          try {
              pstmt.executeQuery(); // Mysql connector throw java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.
          } catch (Exception e) {
          }
          rs = con.createStatement().executeQuery("SELECT * FROM table42_0;");
          while (rs.next()) {
              System.out.println(rs.getObject(1) + " " + rs.getObject(2));
          }
          con.close();
      }
      

      In the test case, MariaDB connector inserts successfully while MySQL connector does not. Therefore, the results of select query after pstmt.executeQuery() are affected.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            dwenking Wenqian Deng
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.