Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Query Timeout from NamedParameterJdbcTemplate

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.

like image 576
mmaynar1 Avatar asked Oct 24 '25 04:10

mmaynar1


1 Answers

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);
like image 84
JB Nizet Avatar answered Oct 25 '25 18:10

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!