springjdbc

JDBC - Multiple queries in NamedParameterJdbcTemplate


Is there any way I can execute more than 1 query using a NamedParameterJdbcTemplate in one single call?


Solution

  • The simple answer: You can't. JDBC statements should execute only one query / statement at a time.

    The longer answer: You usually can't, because either the driver or the database server doesn't support it, and formally the JDBC specification doesn't allow for it (if you read a bit between the lines in both the specification and the Javadoc). However, some drivers (e.g. MySQL Connector/J) do allow you to execute multiple queries in one go (though you may need to specify a connection property to enable it).