我为我的网站改变了主机公司,我在其中使用了mySQL数据库.我不时会收到此错误:No operations allowed after connection closed.我记得第一次在旧服务器上运行我的网站时遇到了同样的问题,我用“配置修复”修复了问题...
我为我的网站改变了主机公司,我在其中使用了mySQL数据库.
我不时会收到此错误:
No operations allowed after connection closed.
我记得第一次在旧服务器上运行我的网站时遇到了同样的问题,我用“配置修复”修复了问题而不是“代码修复”,但我不记得我做了什么:(
我在这里阅读了mant帖子,但每次都谈到代码修复,我不认为这是我的情况
有人能帮我吗?
谢谢
编辑
我在旧的context.xml文件中找到了这个;可能这是我解决问题的方法
validationQuery="SELECT 1"
testOnBorrow="true"
testOnBorrow:(boolean)指示在从池中借用对象之前是否验证对象.如果对象无法验证,它将从池中删除,我们将尝试借用另一个.注 – 要使true值生效,必须将validationQuery参数设置为非空字符串.默认值为false
validationQuery:(String)在将它们返回给调用者之前,将用于验证来自此池的连接的SQL查询.如果指定,此查询不必返回任何数据,它只是不能抛出SQLException.默认值为null.示例值为SELECT 1(mysql),从双(oracle)中选择1,SELECT 1(MS Sql Server)
有人可以证实吗?
解决方法:
您可以在JDBC连接URL中使用autoReconnect = true参数:(例如:“jdbc:mysql:// localhost:3306 / my-db?autoReconnect = true”).
但请注意,如果您的应用程序无法正确处理SQLExceptions,这可能会导致问题.
从MySql文档:
autoReconnect
Should the driver try to re-establish stale and/or dead connections? If > enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don’t handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, as a last option, investigate setting the MySQL server variable “wait_timeout” to a high value, rather than the default of 8 hours.
本文标题为:java – 在mysql上关闭连接后不允许任何操作
- Java二分查找算法与数组处理的应用实例 2023-03-11
- Java实战宠物店在线交易平台的实现流程 2023-08-11
- Java中List转Map List实现的几种姿势 2022-11-29
- Java多线程并发与并行和线程与进程案例 2023-01-08
- 关于mybatis使用${}时sql注入的问题 2023-08-07
- 基于OpenID Connect及Token Relay实现Spring Cloud Gateway 2023-01-29
- Java递归查找层级文件夹下特定内容的文件的方法 2023-01-09
- java实现在原有日期时间上加几个月或几天 2023-06-23
- SpringBoot如何配置获取request中body的json格式参数 2023-02-10
- Java数据结构之线段树的原理与实现 2023-01-08