[CONJ-44] PreparedStatement may not parse ' (') correctly Created: 2013-06-15  Updated: 2013-06-15  Resolved: 2013-06-15

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.2
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Telmo Brugnara Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None
Environment:

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();
	}
}


Generated at Thu Feb 08 03:12:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.