2

I'm getting an error by executing jdbc.update(sql, params) and I would like to see the sql that is executing jdbc.update but with the final values instead :param that is in the sql before execution.

Is there any method of JdbcTemplate that allows to do that?

public boolean create(User user) {
    BeanPropertySqlParameterSource params = 
        new BeanPropertySqlParameterSource(user);

    String sql = "INSERT INTO t_user (username, password, email)"
        + " VALUES (:username, :password, :email)";

    return jdbc.update(sql, params) == 1;
}

I need to get sql that is going to execute jdbcTemplate, and it is something like

INSERT INTO t_user (username, password, email)
       VALUES ("name", "password", "[email protected]")

I need this to check if the sql is right, because I have too many parameters to do all that by hand.

2
  • not possible. if you are using sqlserver use MSSQL TRACE application Commented Mar 7, 2014 at 16:19
  • Try adding log4j. See stackoverflow.com/a/1810851/2607501 Commented Mar 10, 2014 at 12:05

1 Answer 1

0

This is how I do it in my code

String DELETE_BY_ID_QUERY = "delete from my_table where id = ?";
....
String id ="a123";

getJdbcTemplate().update(DELETE_BY_ID_QUERY, new Object[] { id });

EDIT: After reading your Edit to question

You can use the API

public int update(PreparedStatementCreator psc) throws DataAccessException

and then pass in an implementation of PreparedStatementCreator for e.g. (SimplePreparedStatementCreator) and print the sql when the PreparedStatement is created. I haven't tried this, but I think you should be able to get it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.