简体   繁体   中英

How can I validate my jdbc connection whether the data base is up running without executing sql query

我正在使用spring jdbc,就我而言,我仅在数据库运行时才必须执行查询并刷新缓存,因此我找不到适合调用Connection对象的任何方法。

If you're using Spring JdbcTemplate you could perhaps use:

public <T> T execute(ConnectionCallback<T> action) throws DataAccessException

Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. This allows for implementing arbitrary data access operations, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

jdbcTemplate .

You could execute an action once the connection is established such a simple query perhaps.

Let me know if that helps.

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