Results 1 to 4 of 4

Thread: Getting query string output after query execution

  1. #1
    Join Date
    Sep 2010
    Posts
    2

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2010
    Posts
    2

    Default

    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!

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •