本文介绍了iBatis执行sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以获得iBatis的执行查询吗?我想重用UNION查询的查询。



例如:

 < sqlMap namespace =userSQLMap> 
< select id =getUserresultClass =UserPackage.User>
SELECT用户名,
密码
FROM table
WHERE id = #value#
< / select>
< / sqlMap>

当我通过



$ b <$执行查询时p $ p> int id = 1
List< User> userList = queryDAO.executeForObjectList(userSQLMap.getUser,id)

我想要 SELECT用户名,密码FROM表WHERE id = 1



有什么方法可以获得查询吗?



谢谢。

解决方案

显示此信息是可行的.iBatis使用一些Logging框架,包括 Log4J

使用 Log4J 创建文件类路径中的log4j.properties 。您必须将下一行放在文件中,例如:

  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.sqlmap.engine.impl.SqlMapClientDelegate = 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

有关其他日志记录框架和详细信息,请参阅


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.

解决方案

It's posible to show this information.iBatis uses some the Logging framework including Log4J.
To use Log4J create file log4j.properties in the class path.You've to put the next lines in the file for example:

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.sqlmap.engine.impl.SqlMapClientDelegate=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

For other logging framework and detail info see this link

这篇关于iBatis执行sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 11:03