how could I log the sql query (with the actual parameters) in java + Spring.
My dev environment
- Java
- Spring JdbcTemplate.
Let me elaborate the question.
My pseudo code is like this.
String sql = "SELECT COLUMN1 FROM MYTABLE WHERE COLUMN2=? "
List<MyVO> MyVOList = getJdbcTemplate().query(sql, new Object[] { date },
new RowMapper...
Now if I wanted to log the sql - with the actual date that was sent to it - I dont know how to do it.
Option 1 : I can always log the SQL and log the parameters seperately, but I want to have the actual SQL in the logs so the support staff could just copy paste the SQL and run it from a SQL client if need be.
Option 2 : I can think of doing a string substituition and creating the SQL in java and then logging it. However, that always leaves the possibility that because of some freak coding error the actual SQL and the logged SQL are different.
Has someone tried to solve this issue and made any progress?
Please share. Thanks.
Note: I have already read the post Log SQL that is communicated with the database. Using this solution is not an option for me. I am working within an enterprise setup and jdbcdslog-exp is not on the approved list of softwares.