java 关于数据库和 JNDI 的验证查询是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15393954/
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
What is a validationQuery with respect to databases and JNDI?
提问by IAmYourFaja
I seem to be having the same exact problem as the poster of this original SO question.
我似乎遇到了与这个原始 SO 问题的海报完全相同的问题。
The problem is, he answered his own question with the following comment:
问题是,他用以下评论回答了自己的问题:
I solved my problem, I added a validationQuery to my JNDI datasource.
我解决了我的问题,我向我的 JNDI 数据源添加了一个验证查询。
Unfortunately, that doesn't mean anything to me, and doesn't help me solve my problem. So I ask: what is a "validationQuery
" with respect to my database (Sybase) and the JNDI entry used to hold the server lookup info?
不幸的是,这对我来说没有任何意义,也不能帮助我解决我的问题。所以我问:validationQuery
关于我的数据库(Sybase)和用于保存服务器查找信息的 JNDI 条目,什么是“ ”?
Thanks in advance.
提前致谢。
回答by rgettman
The validation query is a query run by the data source to validate that a Connection
is still open before returning it. Here's Tomcat's definition of a validation query; scroll down to the middle of section "4. Configure Tomcat's Resource Factory", looking for the "validationQuery" attribute.
验证查询是由数据源运行的查询,用于Connection
在返回之前验证 a是否仍处于打开状态。这是 Tomcat对验证查询的定义;向下滚动到“4. 配置 Tomcat 的资源工厂”部分的中间,查找“validationQuery”属性。
EDIT
编辑
According to this answer, if the validation query fails, no error is thrown; the bad/closed connection is dropped and another connection is created to replace it.
根据这个答案,如果验证查询失败,则不会抛出错误;坏的/关闭的连接被丢弃并创建另一个连接来替换它。
回答by Ori Dar
It has no relevance to JNDI, but JDBC datasources.
它与 JNDI 无关,但与 JDBC 数据源无关。
The validation query is used to validate connections from the datasource connection pool, before those are handed-off to the clients. Usually these are low impact query such as "SELECT 1..." or "SELECT SYSDATE..."
验证查询用于验证来自数据源连接池的连接,然后再将它们传递给客户端。通常这些是低影响查询,例如“SELECT 1...”或“SELECT SYSDATE...”
回答by WeMakeSoftware
I assume it is a query to test if DB connection works fine. Some sort of ping on the app-server level.
我假设这是一个测试数据库连接是否正常的查询。某种应用服务器级别的 ping。
In the original question periodic pinging of the DB keeps the connection opened.
在原始问题中,定期 ping 数据库保持连接打开。