Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
2.2.6
-
None
-
Windows 10
Description
We are facing the below issue with the insert query execution when we have the backslash at the end of the one columns data and a question mark in the other columns data.
java.sql.SQLException: You need to set exactly 1 parameters on the prepared statement
Example:
Table:
CREATE TABLE `book` ( |
`title` varchar(100) DEFAULT NULL, |
`author` varchar(100) DEFAULT NULL |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
Java Code:
String query = "INSERT INTO book (author, title) values ('Ghosh\\\\', 'Do You Know?')"; |
try(PreparedStatement prepareStatement = con.prepareStatement(finalInsertQuery, Statement.RETURN_GENERATED_KEYS);){ |
prepareStatement.addBatch();
|
prepareStatement.executeBatch();
|
}
|
Here I am trying to execute the query "INSERT INTO book (author, name) values ('Ghosh\\', 'Do You Know?')" from Java. Here the author's name is 'Ghosh\', so am escaping it and title is 'Do You Know?' which has ? mark in the data. Here expectation is that not to consider the '?' as placeholder, but its failing with the error - java.sql.SQLException: You need to set exactly 1 parameters on the prepared statement
Attachments
Issue Links
- duplicates
-
CONJ-664 SQLException when backslash (\), which doesn't escape any character, is used together with setParameter()
- Closed