您的位置:首页 > 其它

Log4j打印JdbcTemplate及参数

2015-06-18 17:34 309 查看
项目中使用JdbcTemplate进行DAO层封装,有时需要调试查看SQL语句及参数

首先是SQL语句:

查看了JdbcTemplate的反编译源码,发现打印语句的地方,其日志级别为debug,

因此,添加log4j参数:log4j.logger.org.springframework.jdbc.core.JdbcTemplate=debug

public int update(String sql) throws DataAccessException {
Assert.notNull(sql, "SQL must not be null");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Executing SQL update [" + sql + "]");
}


其后是语句参数:

同样跟踪执行praparedStatement执行过程,添加参数:log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils=debug

最终效果:

17:05:26,034 DEBUG JdbcTemplate:574 - Executing prepared SQL statement [select * from A WHERE ID=?]
17:05:26,459 DEBUG StatementCreatorUtils:207 - Setting SQL statement parameter value: column index 1, parameter value [1111], value class [java.lang.String], SQL type 12
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: