Spring JDBC is not logging SQL with log4j

后端 未结 6 1830
慢半拍i
慢半拍i 2020-12-11 20:06

I\'m researching spring for a possible switch to a spring stack. One of the things that I thought was cool was the ability for spring jdbc to log all the executed sql. So

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 20:50

    How are you executing the SQL? Spring won't magically log SQL that gets sent to the database, you have to go through the appropriate channels.

    For example, if you execute SQL by using JdbcTemplate, either directly or via JdbcDaoSupport, then yes, the SQL will be logged for some operations, but only those operations that involve direct SQL.

    If you use Hibernate or prepared statements, then Spring never gets to see the SQL itself, and therefore cannot log it.

    If you posted some sample code that demonstrated how you were executing your SQL, it would help a lot.

提交回复
热议问题