Announcement Announcement Module
Collapse
No announcement yet.
Getting query string output after query execution Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting query string output after query execution

    Hi all!

    I am new to Spring, and having implemented several query methods, have begun to wonder if it is possible to output the query after it has been executed. For example:

    If I were to run the following query method:

    Code:
    	
    public String selectSerialByID(int equipmentID) { 
    		
    	String query = "SELECT SerialNumber FROM Equipment WHERE EquipmentID = ?";	
    	
            Console.print(query);
    		
    	return (String) getJdbcTemplate().queryForObject(query, new Object[] { Integer.valueOf(equipmentID) }, 
    		new RowMapper <Object>() {
    			public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException {
    				return resultSet.getString("SerialNumber");				
    			}
    		}
    	);
    }
    By some method (unbeknown to me!) I would get:

    SELECT SerialNumber FROM Equipment WHERE EquipmentID = 81


    Any input appreciated.

    Thanks!

  • #2
    No there isn't... The sql is created and parsed by the jdbc provider, parameters are replaced by the database, so no there isn't. You can use logging frameworks to wrap your connection and statement to log the sql into a log file.

    Comment


    • #3
      I am looking at Log4J and Apache Commons logging with the idea of implementing one of them soon, so I will take this into account when I do.

      Many thanks for that Marten!

      Comment


      • #4
        That is not what I meant. You will need something that wraps your jdbc stuff, log4j isn't going to do that for you, neither is commons logging which is just another wrapper for logging. You want something like p6spy, log4jdbc etc.

        Comment

        Working...
        X