Set Query Timeout from NamedParameterJdbcTemplate

7.1k views Asked by At

I'm using the Spring Framework. How can I set the query timeout when using a NamedParameterJdbcTemplate? I notice that JdbcTemplate has a setQueryTimeout(int queryTimeout) method, but I have not been able to find a way to do this with a NamedParameterJdbcTemplate. It has a getJdbcOperations() method, but it appears that setQueryTimeout() is not exposed.

1

There are 1 answers

3
JB Nizet On BEST ANSWER

You should be able to do that by creating a JdbcTemplate, set the query timeout, and then wrap the JdbcTemplate into a NamedParameterJdbcTemplate:

JdbcTemplate template = new JdbcTemplate(...);
template.setQueryTimeout(...);
NamedParameterJdbcTemplate named = new NamedParameterJdbcTemplate(template);