Seeing the underlying SQL in the Spring JdbcTemplate?

后端 未结 7 1012
深忆病人
深忆病人 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:37

    I'm not 100% sure what you're getting at since usually you will pass in your SQL queries (parameterized or not) to the JdbcTemplate, in which case you would just log those. If you have PreparedStatements and you don't know which one is being executed, the toString method should work fine. But while we're on the subject, there's a nice Jdbc logger package here which will let you automatically log your queries as well as see the bound parameters each time. Very useful. The output looks something like this:

    executing PreparedStatement: 'insert into ECAL_USER_APPT
    (appt_id, user_id, accepted, scheduler, id) values (?, ?, ?, ?, null)'
         with bind parameters: {1=25, 2=49, 3=1, 4=1} 
    

提交回复
热议问题