6

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?

YasiuMaster
  • 299
  • 2
  • 5
  • 15
  • 1
    Found that it's possible to override DefaultStatementBuilder : https://groups.google.com/forum/#!topic/jdbi/rfxmdLDQtGs – YasiuMaster Oct 13 '16 at 12:10

2 Answers2

2

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);
});
KnotGillCup
  • 177
  • 1
  • 9
1
Approach1:
@SqlQuery("select count(1) form table")
@QueryTimeout(1)
int findCount()

Approach2:

getHandle()
.createQuery("select count(1) from table")
.setQueryTimeout(1)
.mapTo(Integer.class)
pinaci
  • 353
  • 4
  • 4