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

Wrong error message when calling ParameterMetaData getParameterCount() with incorrect SQL in PreparedStatement

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 2.1.1
    • 1.6.5, 2.1.2
    • Other
    • None

    Description

      When calling getParameterCount() from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

      For example:
      Executing query:

      S1ELECT * from duala WHERE a = ?
      

      fails with

      java.sql.SQLException: Parameter metadata not available for these statement
      

      Corrected version:

      S1ELECT * from duala WHERE a = ?
      

      fails with

      java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1
      

      Attached example:

      	PreparedStatement pstmt = connection.prepareStatement(sql);
      	final ParameterMetaData pmd = pstmt.getParameterMetaData();
      	//wrong error message:
      	final int count = pmd.getParameterCount();
      

      I think one possible workaround is to change setParametersData() method in
      class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it

      private void setParametersData() throws SQLSyntaxErrorException {
      	try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
      			ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
      		resultSetMetaData = ssps.getMetaData();
      		parameterMetaData = ssps.getParameterMetaData();
      	} catch (SQLSyntaxErrorException sqlsse) {
      		// syntax error thrown
      		throw sqlsse;
      	} catch (SQLException sqle) {
      		//if statement cannot be prepared
      		parameterMetaData = new MariaDbParameterMetaData(null);
      	}
      }
      

      Attachments

        Activity

          rafalopez79 Rafael Lopez Fernández created issue -
          rafalopez79 Rafael Lopez Fernández made changes -
          Field Original Value New Value
          Description When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL,
          it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLException: Parameter metadata not available for these statement

          Corrected version:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLException: Parameter metadata not available for these statement

          Corrected version:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          rafalopez79 Rafael Lopez Fernández made changes -
          Description When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLException: Parameter metadata not available for these statement

          Corrected version:
          Executing query: S1ELECT * from duala WHERE a = ?
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          java.sql.SQLException: Parameter metadata not available for these statement

          Corrected version:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          rafalopez79 Rafael Lopez Fernández made changes -
          Description When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          java.sql.SQLException: Parameter metadata not available for these statement

          Corrected version:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with

          {noformat}
          java.sql.SQLException: Parameter metadata not available for these statement
          {noformat}

          Corrected version:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with
          {noformat}
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1
          {noformat}

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          rafalopez79 Rafael Lopez Fernández made changes -
          Description When calling getParameterCount from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with

          {noformat}
          java.sql.SQLException: Parameter metadata not available for these statement
          {noformat}

          Corrected version:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with
          {noformat}
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1
          {noformat}

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          When calling getParameterCount() from the ParameterMetaData of a PreparedStatement with incorrect SQL, it fails with "Parameter metadata not available for these statement" instead of "You have an error in your SQL syntax; ..."

          For example:
          Executing query:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with

          {noformat}
          java.sql.SQLException: Parameter metadata not available for these statement
          {noformat}

          Corrected version:
          {code:sql}
          S1ELECT * from duala WHERE a = ?
          {code}

          fails with
          {noformat}
          java.sql.SQLSyntaxErrorException: (conn=20657507) Error preparing query: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S1ELECT * from duala WHERE a = ?' at line 1
          {noformat}

          Attached example:


          {code:java}
          PreparedStatement pstmt = connection.prepareStatement(sql);
          final ParameterMetaData pmd = pstmt.getParameterMetaData();
          //wrong error message:
          final int count = pmd.getParameterCount();
          {code}

          I think one possible workaround is to change setParametersData() method in
           class org.mariadb.jdbc.MariaDbPreparedStatementClient to capture SQLSyntaxErrorException and to rethrow it


          {code:java}
          private void setParametersData() throws SQLSyntaxErrorException {
          try (MariaDbPreparedStatementServer ssps = new MariaDbPreparedStatementServer(connection, this.sqlQuery,
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, Statement.NO_GENERATED_KEYS)) {
          resultSetMetaData = ssps.getMetaData();
          parameterMetaData = ssps.getParameterMetaData();
          } catch (SQLSyntaxErrorException sqlsse) {
          // syntax error thrown
          throw sqlsse;
          } catch (SQLException sqle) {
          //if statement cannot be prepared
          parameterMetaData = new MariaDbParameterMetaData(null);
          }
          }
          {code}






          diego dupin Diego Dupin made changes -
          Fix Version/s 2.2.0 [ 22557 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.6.5 [ 22628 ]
          diego dupin Diego Dupin made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 2.1.2 [ 22629 ]
          Fix Version/s 2.2.0 [ 22557 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 82585 ] MariaDB v4 [ 135018 ]

          People

            diego dupin Diego Dupin
            rafalopez79 Rafael Lopez Fernández
            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.