I am developing a command line application in JAVA where, based on some factors, MySQL queries are executed on a sandbox MySQL server and after some manual verification these queries need to be executed on the production server. I want to log these MySQL queries in a .sql file on sandbox server and execute it later using scripts.
I tried searching through stack overflow and found lots of examples for logging queries, but the queries logged are not the final queries executed. For example,
Preparing: INSERT into table_name values(null, ?,?, ?,?,?, ?, ?,?);
DEBUG [pool-4-thread-1] - ==> Parameters: 21655(Integer), 2658413(Integer), 04:05:00(Time), null, 1565.0(Double), 3(String), (String), 0(Integer)
Also, the queries are not logged in directly executable format.
My log4j.properties file:
log4j.rootLogger=INFO, stdout
log4j.logger.com.test.mappers.TableMapper=TRACE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
log4j.logger.java.sql.PreparedStatement=DEBUG, stdout
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.com.ibatis=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
Can I log exact final MySQL queries in a .sql file separately?