[CONJ-126] PreparedStatement.setObject() returns IllegalParameterException: No '?' on that position Created: 2014-12-09  Updated: 2014-12-22  Resolved: 2014-12-22

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

Type: Bug Priority: Major
Reporter: Ivan Assignee: Massimo Siani (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Environment:

Java 8, MariaDB connector 1.1.7 remotely connected to MariaDB server 10.0.11-MariaDB



 Description   

The query below works fine with MySQL Connector/J driver. But it produces IllegalParameterException with mariaDB Java driver. The server is MariaDB in both cases.

The query:
REPLACE INTO tblCustomerUDf1 (`BestPracticesNotification`,`SLIndex#orBV#`,`Seems:LikeParam?`,`Webinar1-3QuickSteps`,`Webinar10-TM/ProjComp`,`Webinar2-MSSelling`,`Webinar3-ProductSelling`,`Webinar4-TM/ProjSelling`,`Webinar5-MSDelivery`,`Webinar6-ProductDelivery`, `isM&M'sTasty?`) VALUES (?,?,?,?,?,?,?,?,?,?,?).

The relevant part of stack trace:
org.mariadb.jdbc.internal.common.query.IllegalParameterException: No '?' on that position
at org.mariadb.jdbc.internal.common.query.MySQLParameterizedQuery.setParameter(MySQLParameterizedQuery.java:103)
at org.mariadb.jdbc.MySQLPreparedStatement.setParameter(MySQLPreparedStatement.java:477)
... 89 more

Removing columns with '#' or '?' in names solves the problem. But this is the fail of the driver as MariaDB server legally supports such characters in column names.

After some debugging I figured out that PS parser does not distinguish back-ticks enclosing column names. So it interprets '#' in the column name `SLIndex#orBV#` as a start of the comment. When I remove this column the parser detects parameter placeholder '?' inside the column name `Seems:LikeParam?` etc.

So the parser needs to be improved to respect back-ticks around object names.

The problematic method is org.mariadb.jdbc.internal.common.Utils::createQueryParts

The test table:
CREATE TABLE IF NOT EXISTS `tblCustomerUDf1` (
`customerID1` int(11) NOT NULL,
`BestPracticesNotification` text,
`SLIndex#orBV#` text,
`isM&M'sTasty?` bit(1) DEFAULT NULL,
`Seems:LikeParam?` bit(1) DEFAULT NULL,
`Webinar1-3QuickSteps` text,
`Webinar2-MSSelling` text,
`Webinar3-ProductSelling` text,
`Webinar4-TM/ProjSelling` text,
`Webinar10-TM/ProjComp` text,
`Webinar5-MSDelivery` text,
`Webinar6-ProductDelivery` text

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Thank you,
Ivan


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