我为我的网站改变了主机公司,我在其中使用了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上关闭连接后不允许任何操作


基础教程推荐
- springboot集成mybatisplus的详细步骤 2023-06-17
- java – mongodb-3.6.0的Spring数据 2023-10-31
- Spring BOOT AOP基础应用教程 2023-02-18
- Java SpringBoot集成文件之如何使用POI导出Word文档 2023-03-22
- Java JSch远程执行Shell命令的方法 2022-10-31
- Java实现全排列的三种算法详解 2023-01-18
- Java-Redis-Redisson分布式锁的功能使用及实现 2023-03-30
- SpringBoot注入自定义的配置文件的方法详解 2023-05-24
- 详解java封装返回结果与RestControllerAdvice注解 2023-05-18
- SpringBoot配置文件中密码属性加密的实现 2023-03-11