在Spring JdbcTemplate中看到底层的SQL吗? [英] Seeing the underlying SQL in the Spring JdbcTemplate?

查看:398
本文介绍了在Spring JdbcTemplate中看到底层的SQL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习JdbcTemplate和NamedParameterJdbcTemplate的奇迹.我喜欢我所看到的内容,但是有什么简单的方法可以查看最终执行的底层SQL?我希望将其用于调试目的(例如,在外部工具中调试生成的SQL).

I am learning about the wonders of JdbcTemplate and NamedParameterJdbcTemplate. I like what I see, but is there any easy way to see the underlying SQL that it ends up executing? I'd like to see this for debug purposes (in order to for example debug the resulting SQL in an outside tool).

推荐答案

The Spring documentation says they're logged at DEBUG level:

此类的所有SQL都记录在 DEBUG 级别的类别下,该级别对应于标准的类名称模板实例(通常为JdbcTemplate,但如果使用JdbcTemplate类的自定义子类,则可能会有所不同).

All SQL issued by this class is logged at the DEBUG level under the category corresponding to the fully qualified class name of the template instance (typically JdbcTemplate, but it may be different if you are using a custom subclass of the JdbcTemplate class).

用XML术语,您需要配置记录器,例如:

In XML terms, you need to configure the logger something like:

<category name="org.springframework.jdbc.core.JdbcTemplate">
    <priority value="debug" />
</category>

这个主题在一个月前在这里进行了讨论,它似乎不像在Hibernate中那样容易工作和/或没有返回预期的信息:

This subject was however discussed here a month ago and it seems not as easy to get to work as in Hibernate and/or it didn't return the expected information: Spring JDBC is not logging SQL with log4j This topic under each suggests to use P6Spy which can also be integrated in Spring according this article.

这篇关于在Spring JdbcTemplate中看到底层的SQL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆