论坛首页 入门技术论坛

使用ibatis开发Swing程序配置log4j显示ibatis的sql语句

浏览 3830 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-05-18  

   准备用swing做一个拨号程序,和数据库打交道的地方比较多,所以考虑用ibatis来和数据库交互,在搭框架的时候,调式程序时 sql语句没有被打印出来,所以决定用log4j打印出来,以方便调式。

  我使用的是netbeans6.0.1,在工程的根目录新建一个log4j.properties的文件,然后在里面加上配置:代码如下:

 

ibatis2.3 --log4j 写道
log4j.rootLogger=info,stdout
log4j.debug=true

#ibatis log configure
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.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=DEBUG

 注意这句话:

 

log4j.rootLogger=info,stdout 写道
log4j.rootLogger=info,stdout

 假如不加上这句话的话,那么log4j不会输入sql语句,但是会输入一些null,测试时控制台打印如下:

写道
log4j: Could not find root logger information. Is this OK?
log4j: Parsing for [com.ibatis.common.jdbc.SimpleDataSource] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.common.jdbc.SimpleDataSource set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.common.jdbc.SimpleDataSource=[null]
log4j: Parsing for [java.sql.Connection] with value=[debug].
log4j: Level token is [debug].
log4j: Category java.sql.Connection set to DEBUG
log4j: Handling log4j.additivity.java.sql.Connection=[null]
log4j: Parsing for [com.ibatis] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis set to DEBUG
log4j: Handling log4j.additivity.com.ibatis=[null ]
log4j: Parsing for [com.ibatis.common.jdbc.ScriptRunner] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.common.jdbc.ScriptRunner set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.common.jdbc.ScriptRunner=[null ]
log4j: Parsing for [com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=[null ]
log4j: Parsing for [java.sql.Statement] with value=[debug].
log4j: Level token is [debug].
log4j: Category java.sql.Statement set to DEBUG
log4j: Handling log4j.additivity.java.sql.Statement=[null ]
log4j: Parsing for [java.sql.PreparedStatement] with value=[DEBUG].
log4j: Level token is [DEBUG].
log4j: Category java.sql.PreparedStatement set to DEBUG
log4j: Handling log4j.additivity.java.sql.PreparedStatement=[null ]
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (com.ibatis.common.jdbc.SimpleDataSource).
log4j:WARN Please initialize the log4j system properly.

 只有加上了这句:log4j.rootLogger=info,stdout

 控制台才会输入sql语句:

输入 sql 写道
log4j: Parsing for [root] with value=[info,stdout].
log4j: Level token is [info].
log4j: Category root set to INFO
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %c{1}:%L - %m%n].
log4j: End of parsing for "stdout".
log4j: Setting property [target] to [System.out].
log4j: Parsed "stdout" options.
log4j: Parsing for [com.ibatis.common.jdbc.SimpleDataSource] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.common.jdbc.SimpleDataSource set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.common.jdbc.SimpleDataSource=[null]
log4j: Parsing for [java.sql.Connection] with value=[debug].
log4j: Level token is [debug].
log4j: Category java.sql.Connection set to DEBUG
log4j: Handling log4j.additivity.java.sql.Connection=[null]
log4j: Parsing for [com.ibatis] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis set to DEBUG
log4j: Handling log4j.additivity.com.ibatis=[null]
log4j: Parsing for [com.ibatis.common.jdbc.ScriptRunner] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.common.jdbc.ScriptRunner set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.common.jdbc.ScriptRunner=[null]
log4j: Parsing for [com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate] with value=[debug].
log4j: Level token is [debug].
log4j: Category com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate set to DEBUG
log4j: Handling log4j.additivity.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=[null]
log4j: Parsing for [java.sql.Statement] with value=[debug].
log4j: Level token is [debug].
log4j: Category java.sql.Statement set to DEBUG
log4j: Handling log4j.additivity.java.sql.Statement=[null]
log4j: Parsing for [java.sql.PreparedStatement] with value=[DEBUG].
log4j: Level token is [DEBUG].
log4j: Category java.sql.PreparedStatement set to DEBUG
log4j: Handling log4j.additivity.java.sql.PreparedStatement=[null]
log4j: Finished configuring.
15:05:23,268 DEBUG SimpleDataSource:27 - Created connection 12707029.
15:05:23,331 DEBUG Connection:27 - {conn-100000} Connection
15:05:23,378 DEBUG Connection:27 - {conn-100000} Preparing Statement: select euser_id as userId,eusernamee as username,eusernamec as usernamec,epassword as password,egroup_id as groupId,elevel_id as levelId,earea_id as areaId,eaddr as address,econtact1 as contactOne,econtact2 as contactTwo,email as email from mc$lg_euser where EUSERNAMEC=?
15:05:27,159 DEBUG PreparedStatement:27 - {pstm-100001} Executing Statement: select euser_id as userId,eusernamee as username,eusernamec as usernamec,epassword as password,egroup_id as groupId,elevel_id as levelId,earea_id as areaId,eaddr as address,econtact1 as contactOne,econtact2 as contactTwo,email as email from mc$lg_euser where EUSERNAMEC=?
15:05:27,190 DEBUG PreparedStatement:27 - {pstm-100001} Parameters: [上帝发誓 ]
15:05:27,237 DEBUG PreparedStatement:27 - {pstm-100001} Types: [java.lang.String]
15:05:29,612 DEBUG SimpleDataSource:27 - Returned connection 12707029 to pool.
 

 

   发表时间:2009-05-18  
15:05:27,190 DEBUG PreparedStatement:27 - {pstm-100001} Parameters: [上帝发誓 ]
15:05:27,237 DEBUG PreparedStatement:27 - {pstm-100001} Types: [java.lang.String]
15:05:29,612 DEBUG SimpleDataSource:27 - Returned connection 12707029 to pool.
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics