Bug #90299 Prepared statements in Connector/J with question marks in fields fail
Submitted: 4 Apr 2018 9:06 Modified: 4 Apr 2018 14:19
Reporter: MC Brown Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.42 OS:Any
Assigned to: CPU Architecture:Any

[4 Apr 2018 9:06] MC Brown
Description:
When using prepared statements through Connector/J on a table which has question marks in the field names, Connector/J gets confused about the parameters it should be substituting and ultimately reports an error about the number of values that should be supplied to the prepared statement. 

The number of statements expected matches the number of question marks in the overall statement that is probably generated, not the actual number of substitutions. 

This was originally found on a table created by a third-party tool (Zoho) which includes question marks in the columns. 

How to repeat:
Create a table with fields as question marks: 

CREATE TABLE `question` (
  `a?` int(11) NOT NULL AUTO_INCREMENT,
  `b?` char(80) DEFAULT NULL,
  PRIMARY KEY (`a?`)
);

Try to insert data into the table through Connector/J and prepared statements. 

You'll get an error that the number parameters to the prepared statement is incorrect: 

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

Suggested fix:
It appears Connector/J is just taking the question marks and trying to replace the content with the supplied parameters, but obviously the question marks in the column names should be ignored.
[4 Apr 2018 11:36] Chiranjeevi Battula
Hello Brown,

Thank you for the bug report.
I could not repeat the issue at our end using with Connector / J  5.1.46, MySQL 5.7.21 version.
Please use insert query like "String query = " insert into question (`b?`) values (?)".

Thanks,
Chiranjeevi.
[4 Apr 2018 14:19] MC Brown
I built a new test case for this and have not been able to reproduce under the original conditions. 

As such, I'll mark this closed.