通过JDBC“ping”数据库的最佳方法是什么? [英] What is the best way to 'ping' a database via JDBC?

查看:86
本文介绍了通过JDBC“ping”数据库的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定通过JDBC ping数据库的最佳方法。 最好是指快速和低开销。例如,我考虑过执行此操作:

 SELECT 1 FROM DUAL

但我认为DUAL表是特定于Oracle的,我需要更通用的东西。



<请注意 Connection 有一个 isClosed()方法,但是javadoc声明这不能用于测试连接的有效性。

解决方案

是的,这只是Oracle,但在JDBC中没有通用的方法。



大多数连接池实现都有一个配置参数,您可以在其中指定将用于ping的SQL,从而推动责任制定如何对其进行操作。用户。



这似乎是最好的方法,除非有人为此提出一个小帮助工具(当然,它排除了使用可能更快的非基于SQL的方法,如< a href =http://www.orindasoft.com/public/Oracle_JDBC_JavaDoc/javadoc1110/oracle/jdbc/OracleConnection.html#pingDatabase()\"rel =noreferrer> Oracle的内部ping功能)


I'm trying to determine the best way to ping a database via JDBC. By 'best' I mean fast and low overhead. For example, I've considered executing this:

"SELECT 1 FROM DUAL"

but I believe the DUAL table is Oracle-specific, and I need something more generic.

Note that Connection has an isClosed() method, but the javadoc states that this cannot be used to test the validity of the connection.

解决方案

Yes, that would be Oracle-only, but there is no generic way to do this in JDBC.

Most connection pool implementations have a configuration parameter where you can specify the SQL that will be used for ping, thus pushing the responsiblity to figure out how to do it to the user.

That seems like the best approach unless someone comes up with a little helper tool for this (of course, it precludes using potentially even faster non-SQL-based methods like Oracle's internal ping function)

这篇关于通过JDBC“ping”数据库的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆