简体   繁体   English

JDBC SQL Server查询超时

[英]JDBC SQL Server query timeout

I'm working on a Java application built with Maven. 我正在使用Maven构建Java应用程序。 The application works with data from a local SQL Server database. 该应用程序使用本地SQL Server数据库中的数据。 Is is very common for the SQL Server at my workplace to be unavailable (several power outages), so I'd like to set a shorter timeout for the system to throw an exception. 对于我的工作场所中的SQL Server不可用(几次停电),这是很常见的,因此我想为系统设置一个较短的超时以引发异常。

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection

The idea is not to have the application hanging for ~30 seconds before letting us know the server is unavailable. 我们的想法是在让我们知道服务器不可用之前,不要将应用程序挂起约30秒。

I've tried including the socketTimeout and queryTimeout properties in the Datasource's URL as indicated in these two links, but to no avail. 我试图按照 两个链接中的指示在数据源的URL中包含socketTimeout和queryTimeout属性,但无济于事。 Is there any way to set a global timeout for this? 有什么办法为此设置全局超时吗?

Via jdbcTemplate: 通过jdbcTemplate:

JdbcTemplate template = new JdbcTemplate(dataSource);
template.setQueryTimeout(30);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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