Dashboard > iBATIS DataMapper > Home > Frequently Asked Questions > How do I get SqlMapClient to log SQL statements
How do I get SqlMapClient to log SQL statements
Added by Clinton Begin, last edited by Robert D. MacDonald on Jul 05, 2008  (view change)
Labels: 
(None)


iBATIS uses commons-logging to log these.

Depending on your logging implementation, your configuration may vary.

If you are using log4j, put this line into log4j.properties:

log4j.logger.java.sql=DEBUG

If you set your default log level to DEBUG, that will work, too...but you will get debug level logging for everything in the world.

Here is another example of how to configure ibatis with log4j using an xml config file.

log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    
    <!-- Console output -->
    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss} %m  (%F:%L) \n"/>
    </layout>
    </appender>
    
    <category name="com.ibatis">
    <priority value="debug" />
    </category>
    
    <category name="java.sql">
    <priority value="debug" />
    </category>
    
    <!--The root category defines the top level of appenders all catagories inherit -->
    
    <root>
    <priority value ="error" />
    <appender-ref ref="STDOUT" />
    </root>
    
    
    </log4j:configuration>

A common question is "Is it possible to show the ACTUAL query being executed?".

The simple answer is NO.

Why? Because the only information we have available is the PreparedStatement and the parameters.

Quite often, in the process of applying those parameters to the mapped statement it will become very clear where issues lie in the execution of the query.

If you feel that you NEED to see the completed query, you may be interested in hooking up a debugging tool like p6spy, as it may answer your questions for you.

For WebSphere-specific instructions see also How do I Configure Logging in WebSphere.


Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators