Sometimes it’s a good idea to intercept the SQL queries exactly as they are generated by your Java application. One way to do it (in MySQL) is to enable general_log. Another really handy option is to use MySQL JDBC driver option: autoGenerateTestcaseScript. It will dump all the queries to standard error, as they are being sent to the database.

com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
ds.setAutoGenerateTestcaseScript(true);
ds.setURL("jdbc:mysql://host:port/dbname");
Connection con = ds.getConnection("user", "password");
//...

This will give you on your stderr output like this:

<p>
<br>
/* conn id 384 */ SELECT * FROM user WHERE id = 2;<br>
/* conn id 384 */ SELECT * FROM user WHERE id = 1;<br>

</p>