Is there any way to set jdbc query timeout globally in java project

1.4k Views Asked by At

Can we set Query timeout globally (i.e. in DataSource configure, spring application properties file or somewhere).As i have to write everywhere in my project in which Statement / PreparedStatement used.

I have seen only two ways to set query timeout yet. But it works only one preparedStatement/statement at a time. see below code.

preparedStatement.setQueryTimeout(30); or PoolUtilities.setQueryTimeout(preparedStatement, 30);

I could not found any solution for this. Please let me know if you know to set simple jdbc query timeout on global level

1

There are 1 best solutions below

0
On BEST ANSWER

You can use CONNECTION_PROPERTY_THIN_READ_TIMEOUT for Oracle thin driver. Add to datasource as follows

properties.put(OracleConnection.CONNECTION_PROPERTY_THIN_READ_TIMEOUT, readTimeoutMillis.toString());
dataSource.setConnectionProperties(properties);