0

I'm making a developer tool as a Webservice. One of the requirements is that the developer tool should be able to return the prepared statement used by Mybatis as a string. However, I'm not quite sure how to get the prepared sql statement that is used by Mybatis as an object.

Any tips would be great.

After further investigation. I stumbled upon this post:

How can I get the SQL of a PreparedStatement?.

However, I am still wondering if there is any way that I can actually contact the server and see the analyzed prepared SQL statement? i.e. check the logs of my database or some connection template?

Community
  • 1
  • 1
BenBitdiddle
  • 1
  • 1
  • 2
  • see if this helps http://stackoverflow.com/questions/13195144/can-i-use-mybatis-to-generate-dynamic-sql-without-executing-it/ – Bogdan Jan 07 '15 at 21:01

1 Answers1

0

You can use Mybatis logging for SQL statement.
It's produce SQL prepare statements log like below :

Preparing: SELECT USER_ID AS userId, PASSWORD AS password, USER_NAME AS userName FROM USER_MST WHERE USER_NAME = ? AND PASSWORD = ? AND DELETE_FLAG = 0 
Parameters: test_uname(String), test_pass(String)

Here is the Mybatis logging documentation.

Below is the sample log configuration for mybatis.

<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
    debug="false">

    <appender name="APPLICATION" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="C:/log/mybatis.log" />
        <param name="MaxBackupIndex" value="10" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} |%5p| [%c] | %m%n" />
        </layout>
    </appender>


    <logger name="YourMapperXML" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="APPLICATION" />
    </logger>


</log4j:configuration>
Ye Win
  • 2,020
  • 14
  • 21