Seeing the underlying SQL in the Spring JdbcTemplate?

后端 未结 7 988
深忆病人
深忆病人 2020-11-30 02:24

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 execut

7条回答
  •  有刺的猬
    2020-11-30 02:47

    Parameter values seem to be printed on TRACE level. This worked for me:

    log4j.logger.org.springframework.jdbc.core.JdbcTem plate=DEBUG, file
    log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils=TRACE, file
    

    Console output:

    02:40:56,519 TRACE http-bio-8080-exec-13 core.StatementCreatorUtils:206 - Setting SQL statement parameter value: column index 1, parameter value [Tue May 31 14:00:00 CEST 2005], value class [java.util.Date], SQL type unknown
    02:40:56,528 TRACE http-bio-8080-exec-13 core.StatementCreatorUtils:206 - Setting SQL statement parameter value: column index 2, parameter value [61], value class [java.lang.Integer], SQL type unknown
    02:40:56,528 TRACE http-bio-8080-exec-13 core.StatementCreatorUtils:206 - Setting SQL statement parameter value: column index 3, parameter value [80], value class [java.lang.Integer], SQL type unknown
    

提交回复
热议问题