I'm using Spring's JdbcTemplate (Spring version 4.1.4). With my class' JdbcTemplate instance, I'm doing a select query as a prepared statement. However, my query unexpectedly returns no results. As such, I really need to debug my query and make sure that the query is what I expect it ought to be.
How can I get back the actual SQL that is executed against the DB as part of the JdbcTemplate's internal PreparedStatement?
I'm familiar with the using the PreparedStatement's toString() method to accomplish this, but as JDBCTemplate uses PreparedStatement internally, I'm not sure how feasible it is using Spring.
Some sample code I am using is as follows:
private static final String PREPARED_QUERY =
"select\n" +
" spm.amount\n" +
"from\n" +
" search_price_modifier spm\n" +
"where\n" +
" spm.search_id = ?\n" +
" and spm.search_date > to_date(?, 'MM-DD-YYYY HH24:MI:SS')\n" +
" and spm.search_date < to_date(?, 'MM-DD-YYYY HH24:MI:SS')\n";
public void runQuery(String searchId, String strSearchDateInfimum,
String strSearchDateSupremum) {
SqlRowSet amounts = this.jdbcTemplate.queryForRowSet(
PREPARED_QUERY_FOR_FLAT_MARKUP_VERIFICATION,
searchId, strSearchDateInfimum, strSearchDateSupremum);
while (amounts.next()) {
float amount = amounts.getFloat("AMOUNT");
LOGGER.debug("amount=" + amount);
}
}