Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iBatis get executed sql

Tags:

java

sql

ibatis

Is there any way where I can get the executed query of iBatis? I want to reuse the query for an UNION query.

For example:

<sqlMap namespace="userSQLMap">
   <select id="getUser" resultClass="UserPackage.User">
        SELECT username,
               password 
        FROM table 
        WHERE id=#value#
   </select>
</sqlMap>

And when I execute the query through

int id = 1
List<User> userList = queryDAO.executeForObjectList("userSQLMap.getUser",id)

I want to get SELECT username, password FROM table WHERE id=1

Is there any way I could get the query?

Thanks.

like image 689
qaxi Avatar asked Apr 14 '10 05:04

qaxi


People also ask

How does iBATIS work?

How iBATIS works. iBATIS allows loose coupling of the database and application by mapping the input to and output from the database to the domain objects, thus introducing an abstraction layer. The mapping is done using XML files that contain SQL queries.

Does MyBatis use JDBC?

MyBatis does four main things: It executes SQL safely and abstracts away all the intricacies of JDBC. It maps parameter objects to JDBC prepared statement parameters. It maps rows in JDBC result sets to objects.

What is org Apache iBATIS?

iBATIS was a data mapper framework that made it easier to use a relational database with object-oriented applications.


1 Answers

Add this to your log4j.xml file and you can see the output on console.

<logger name="java.sql" additivity="false">
    <level value="debug" />
    <appender-ref ref="console" />
</logger>

You will see the parameters being passed, the query being executed and the output of query.

like image 80
vsingh Avatar answered Sep 27 '22 19:09

vsingh