简体   繁体   中英

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

Can we set Query timeout globally (ie 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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM