MySQL JDBC + prepared statements -> plain SQL in log

View: New views
2 Messages — Rating Filter:   Alert me  

MySQL JDBC + prepared statements -> plain SQL in log

by Ondrej Zizka-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm sending some prepared statements to MySQL 5.0 using JDBC Driver
Connector/J 5.x :

ps = conn.prepareStatement("INSERT INTO table SET txt = ?");
...

But according to the log, Connector converts them to plain text SQL
statements ---
      143 Query       INSERT INTO table SET txt = 'aXa6'
      143 Query       INSERT INTO table SET txt = 'aXa7'
      143 Query       INSERT INTO table SET txt = 'aXa8
...
---  although MySQL is capable of prepared statements  - according to the
docs, JDBC can do them to:

MySQL 5.0 provides support for server-side prepared statements. This support
takes advantage of the efficient client/server binary protocol implemented
in MySQL 4.1, provided that you use an appropriate client programming
interface. Candidate interfaces include the MySQL C API client library (for
C programs), MySQL Connector/J (for Java programs), and MySQL Connector/NET.

Do I have to turn something on for the JDBC connection or where is the
problem?
Or, does MySQL log the statements with the values inserted to the prepared
statement?

Thanks, Ondra




--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java?unsub=lists@...


Re: MySQL JDBC + prepared statements -> plain SQL in log

by robs888 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try with these params in your connection URL:

useServerPrepStmts=true (default is false)
emulateUnsupportedPstmts=false (default is true)

and your log will show this:

3 Prepare [2] SELECT * FROM users WHERE SourceId=?
3 Prepare [3] INSERT INTO users (UserId,FirstName,MiddleInitial,LastName,...) VALUES (?,?,?,?,...)

3 Execute [2] SELECT * FROM users WHERE SourceId='25768F9388DC834EC12570ED00578668'
3 Execute [3] INSERT INTO users (UserId,FirstName,MiddleInitial,LastName,...) VALUES ('33',...)

see also here: http://dev.mysql.com/doc/refman/5.0/en/cj-news-5-0-5.html

robs
LightInTheBox - Buy quality products at wholesale price!