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

Issue with escape character + question mark

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 2.2.6
    • 2.4.0
    • Other
    • None
    • Windows 10

    Description

      We are facing the below issue with the insert query execution when we have the backslash at the end of the one columns data and a question mark in the other columns data.

      java.sql.SQLException: You need to set exactly 1 parameters on the prepared statement

      Example:

      Table:

      CREATE TABLE `book` (
        `title` varchar(100) DEFAULT NULL,
        `author` varchar(100) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
      

      Java Code:

      String query = "INSERT INTO book (author, title) values ('Ghosh\\\\', 'Do You Know?')";
      try(PreparedStatement prepareStatement = con.prepareStatement(finalInsertQuery, Statement.RETURN_GENERATED_KEYS);){
      prepareStatement.addBatch(); 
      prepareStatement.executeBatch(); 
      }
      

      Here I am trying to execute the query "INSERT INTO book (author, name) values ('Ghosh\​\​', 'Do You Know?')" from Java. Here the author's name is 'Ghosh\', so am escaping it and title is 'Do You Know?' which has ? mark in the data. Here expectation is that not to consider the '?' as placeholder, but its failing with the error - java.sql.SQLException: You need to set exactly 1 parameters on the prepared statement

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              igar Venkatesh
              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.