I am using PreparedStatements
.
When I am try to print the query by using stmt.toString();
, it prints following to console,
com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy
How can I print my query?
I am using PreparedStatements
.
When I am try to print the query by using stmt.toString();
, it prints following to console,
com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy
How can I print my query?
I had a similar but not identical issue; I'll post my solution here in case it will be useful to others:
when I did System.out.println(stmt.toString());
I would get:
"HikariProxyPreparedStatement@172796470 wrapping com.mysql.jdbc.JDBC42PreparedStatement@268fac52: SELECT . . . (rest of query here)"
but after some experimentation I changed it to
System.out.println(stmt.unwrap(com.mysql.jdbc.JDBC42PreparedStatement.class).asSql());
and now I get just the query. The unwrap() method returns the underlying JDBC PreparedStatement.
In general, the toString()
behaviour of a PreparedStatement is implementation-specific: Get query from java.sql.PreparedStatement
Looks like what you've got is actually part of HikariCP's prepared statement cache, which wraps the JDBC driver's own PreparedStatement. To get the string out of it you'd need to access the underlying PreparedStatement and hope you're using one of the drivers that supports this. (I'm having trouble figuring out if this is possible, looks like this area of HikariCP has been substantially refactored: github)