[CONJ-60] Java Client's MySQLPreparedStatement.toString() does not print SQL statement, like Connector/J's class does Created: 2013-08-05  Updated: 2013-09-10  Resolved: 2013-09-05

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

Type: Bug Priority: Minor
Reporter: Daniel Kessel Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None


 Description   

MySQL Connector/J's PreparedStatement class outputs the generated SQL Statement when toString() is called. This is used for logging in applications. Example of the output:

com.mysql.jdbc.PreparedStatement@500fbfa2: SELECT id FROM table WHERE someRow='abc'

As one can see, it is trivially to parse the SQL statement from the output of toString() - just get the string after the substring ": ". Or even more simple, just logging the output of toString() might suffice for some logs.

I have an application which is originally written with Connector/J in mind. If I use Connector/J, I get useful log output - it even outputs the statement with the parameter values set.

It would generally reduce cost for application developers if the MariaDB Java Client would output the statement that way, too - for example, the returned String could look like this:

org.mariadb.jdbc.MySQLPreparedStatement@500fbfa2: SELECT id FROM table WHERE someRow='abc'



 Comments   
Comment by Vladislav Vaintroub [ 2013-09-05 ]

Hi Daniel.
My fix would make output of PreparedStatement.toString() more meaningful, however it won't be resolving the ? placeholders . Instead it will output the string with placeholders, and all the parameters that were set. I hope this is fine, we're not aiming 100% ConnectorJ compatibility , and frankly, things like toString() form are not covered by any standard , and are subject to change even if you are using new version of the same product. So I would not bet on ConnectorJ staying forever with their current PreparedStatement.toString().

Comment by Daniel Kessel [ 2013-09-10 ]

Vladislav, thank you very much for solving this issue that fast!

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