java jdbc 验证查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4978594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:55:12  来源:igfitidea点击:

jdbc validation query

javavalidationjdbc

提问by joshjdevl

Is there a library which can determine for a jdbc driver class the appropriate validation query to use?

是否有一个库可以为 jdbc 驱动程序类确定要使用的适当验证查询?

For example If the jdbc driver is com.mysql.jdbc.Driver or com.mysql.jdbc.jdbc2.optional.MysqlXADataSource the library will know the validation query is "SELECT 1"

例如,如果 jdbc 驱动程序是 com.mysql.jdbc.Driver 或 com.mysql.jdbc.jdbc2.optional.MysqlXADataSource,库将知道验证查询是“SELECT 1”

c3po http://www.mchange.com/projects/c3p0/index.html#preferredTestQuery

c3po http://www.mchange.com/projects/c3p0/index.html#preferredTestQuery

dbcp http://commons.apache.org/dbcp/configuration.html"validationQuery"

dbcp http://commons.apache.org/dbcp/configuration.html“验证查询”

回答by joshjdevl

JDBC type 4 provides an isValid method

JDBC 类型 4 提供了一个 isValid 方法

回答by duffymo

I don't think a library is the appropriate place for such a thing.

我认为图书馆不适合做这样的事情。

If you're using a connection pool, it's more likely that you'll ask it to check connections before handing them out. You'll simply enter the appropriate SQL and let the pool handle it. A library would be a step back, because it suggests that your code would be calling it.

如果您使用的是连接池,则更有可能要求它在分发连接之前检查连接。您只需输入适当的 SQL 并让池处理它。库会退一步,因为它表明您的代码将调用它。