Bug #25449 Connector/J counts the '?' in comments when preparing a statement
Submitted: 7 Jan 2007 3:36 Modified: 7 Jan 2007 19:54
Reporter: Gregory Gerard Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.14 OS:Windows (Windows, Linux)
Assigned to: CPU Architecture:Any
Tags: comment, Parameter, prepared statement, question mark

[7 Jan 2007 3:36] Gregory Gerard
Description:
While chasing down a Hibernate issue, I turned on Hibernate's debugging. One option is have the HQL used to generate the SQL prefix it in a comment.

/* from Giblet where theGiblet.mName = ? and theGiblet.mAge = ? */ select * from Giblet g where g.Name = ? and g.Age = ? limit ?

Connector/J counts the '?' without regard to context. Instead of having 3 parameters expected, it expects 5 and throws a JDBC exception.

How to repeat:
Hibernate plus a Query like above.

Suggested fix:
Skip over comment blocks.
[7 Jan 2007 13:51] Mark Matthews
Duplicate of BUG#25025, already fixed in the 5.0 source repository and available in nightly builds of Connector/J 5.0 from http://downloads.mysql.com/snapshots.php#connector-j
[8 Jan 2007 1:35] Mark Matthews
There are no plans to backport this to the 3.1 branch, as 5.0 is the current stable branch (and has been for some time), which means 3.1 gets only data corrupting or security fixes applied to it unless there are extenuating circumstances.

If you're not using XA, 5.0 is not substantially different than 3.1, but does perform slightly better in most situations than 3.1, so it's worth a shot to test your application with it.