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

查看:28
本文介绍了在 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).

推荐答案

Spring 文档 说他们是在调试级别记录的:

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 中那么容易开始工作和/或它没有返回预期的信息:Spring JDBC 未使用 log4j 记录 SQL 每个下的这个主题建议使用 P6Spy 也可以根据 这篇文章.

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天全站免登陆