Tuesday, 11 June 2013

Showing logs on MyBatis with eclipse

MyBatis is a framework mainly done for Java which allow the use of dynamic SQLs. By default it does not print logs of the SQL generated. If you wish it to print the SQLs, you can do the follow:

1. Downlod the log4j jar from here:

2. Include it in your project
2.1 Creates a folder called "lib" in your project directory.
2.2 Copy and paste the jar file on it.
2.3 Go to eclipse and refresh the project
2.4 On the library folder, right click on the new jar and select "Build with" -> "Add to build path"

3. Create the configuration file
3.1 Create a new text file called log4j.properties and paste the follow content on it:

log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.SQL Map.engine.impl.SQL MapClientDelegate=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


3.2 Save it on the class bin folder of your project.

Source:
StackOverFlow: http://stackoverflow.com/questions/2635058/ibatis-get-executed-sql

No comments:

Post a Comment