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

PreparedStatement may not parse ' (') correctly

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.2
    • None
    • None
    • None
    • Tested on Windows 7

    Description

      When using preparedStatement, mariadb java client does not parse ' ( ' ) correctly if they are the last chacacter inside a string.

      Simple (non-prepared) Statement and Mysql Connector/J works OK

      The following class reproduces the issue:

      Test.java

      import java.sql.*;
       
      public class MariaDBTest {
      	static Connection con;
      	
      	public static void main(String[] args) throws Exception {
      		Class.forName("org.mariadb.jdbc.Driver");
      		//Class.forName("com.mysql.jdbc.Driver");
      		String dbUrl = "jdbc:mysql://localhost:3306/";
      		con = DriverManager.getConnection(dbUrl, "root", "root");
      		System.out.println("Connected to " + dbUrl);
      		
      		exec("CREATE DATABASE IF NOT EXISTS test");
      		exec("USE test");
      		exec("DROP TABLE IF EXISTS `test1`");
      		exec("CREATE TABLE `test1` (`col1` varchar(50))");
      		exec("INSERT INTO `test1` VALUES ('\\'a')"); //works
      		exec("INSERT INTO `test1` VALUES ('\\'')");  //does not works
       
      		con.close();
      		System.out.println("Exiting with no errors");
      	}
      	
      	static void exec(String sql) throws SQLException {
      		System.out.println("sql: "+sql);
      		// error occurs only with prepared statement 
      		//con.createStatement().executeUpdate(sql);
      		con.prepareStatement(sql).executeUpdate();
      	}
      }

      Attachments

        Activity

          People

            wlad Vladislav Vaintroub
            tbrugz Telmo Brugnara
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.