Seeing the underlying SQL in the Spring JdbcTemplate?

后端 未结 7 1022
深忆病人
深忆病人 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 02:50

    This worked for me with log4j2 and xml parameters:

    
    
        
            /some_path/logs/
            my_app
        
    
        
            
                
                    [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                    
                
                
                    
                
            
    
            
                
            
        
        
    
            
                
                
            
    
            
                
                
            
        
    
    
    

    Result console and file log was:

    JdbcTemplate - Executing prepared SQL query
    JdbcTemplate - Executing prepared SQL statement [select a, b from c where id = ? ]
    StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [my_id], value class [java.lang.String], SQL type unknown
    

    Just copy/past

    HTH

提交回复
热议问题