sql - how to get the prepared statement query after binding -
i using prepared statement this
preparedstatement pstmt = getconnection().preparestatement(insert_query); pstmt.setint(1,userdetails.getusersid()); log.debug("sql inserting child transactions " + pstmt.tostring());
i want log exact sql statement after binding log file thing not working. logging sqlserverpreparedstatement:7
. searched on internet did not satisfactory answer. appreciated.
you can try enable jdbc internal logging setting printwriter on drivermanager. log4j2 provides io streams module can include output in normal log file. sample code:
printwriter logger = iobuilder.forlogger(drivermanager.class) .setlevel(level.debug) .buildprintwriter(); drivermanager.setlogwriter(logger);
in addition, individual jdbc drivers provide proprietary logging mechanisms, enabled system property. need consult documentation specific driver details.