Reputation: 309
1) Is it possible to set up global value of queryTimout for Dropwizard's JDBI mysql connector? What is the default value? I dont want to use @QueryTimeOut in every single DAO.
2) And what about java.sql.Statement.Connection where is networkTimeout parameter, which is defined as:
number of milliseconds the driver will wait for a database request to complete. If the limit is exceeded, a SQLException is thrown.
Should I consider that as a query timeout?
Upvotes: 6
Views: 3632
Reputation: 353
Approach1:
@SqlQuery("select count(1) form table")
@QueryTimeout(1)
int findCount()
Approach2:
getHandle()
.createQuery("select count(1) from table")
.setQueryTimeout(1)
.mapTo(Integer.class)
Upvotes: 1
Reputation: 175
You can configure a statement consumer that would inject it for every single statement. It can be set on the configurable JDBC wrapper: org.jdbi.v3.core.Jdbi Something like:
Jdbi.create(datasource)
.configure(SqlStatements.class, stmt -> {
stmt.setQueryTimeout(timeout);
});
Upvotes: 2