Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query timeout for JDBI

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?

like image 977
YasiuMaster Avatar asked Oct 29 '22 18:10

YasiuMaster


1 Answers

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);
});
like image 189
KnotGillCup Avatar answered Nov 15 '22 06:11

KnotGillCup