How to log SQL query while using iBatis with annotation.
public interface a {
@Select(select * from tableName where id=#{id})
public tablePojo getObject(@Param("id") String id);
}
How can I log what query iBatis is executing when id
value is passed?
You have to activate the logs for the java.sql
package.
After you do that, you'll get the queries, parameters and rows in your logs.
If you are using Log4j for logging you could add something like this in the log4j.properties
file:
log4j.rootLogger=fatal, consoleAppender
log4j.logger.java.sql=DEBUG, consoleAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%d{dd/MM/yyyy\tHH:mm:ss}\t%C\t%p\t%m%n
You could also add a logger for org.apache.ibatis
and see other additional stuff in the console:
log4j.logger.org.apache.ibatis=DEBUG, consoleAppender