从数据库方面解决org.hibernate.exception.JDBCConnectionException:could not execute query

世界很美好,感谢身边的一切.

---幸运皮

或者是报错:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communicationslink failure

网站部署好之后是可以好好运行的,但是,总是隔一段时间就会报org.hibernate.exception.JDBCConnectionException:could not executequery错误,在网上查了一下说是因为mysql数据库默认连接时间的问题,mysql默认连接时间是8个小时,所以,一般如果访问不多的网站来说,如果隔8个小时没有与数据库的连接,那就会报这个错误.

查了一些资料,有两大方向的解决方案吧:

一. 修改数据库设置

步骤一:进入数据库,看一下wait_timeout 的值:

Show global variables like ‘wait_timeout’;


28800秒就是8小时

步骤二:修改wait_timeout的值:

Set global  wait_timeout=1814400;


看一下变了没有:


步骤三:最后重启tomcat.

这种方法有一个局限,那就是这样设置的话,总有一个时间限制.所以,最好使用下面的方法.

二. 使用数据库连接池.

这个方法还没有测试成功.但是这个应该是最好的解决方法.



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:根据您提供的引用内容,报错信息显示为"could not prepare statement; nested exception is org.hibernate.exception.JDBCConnectionException: could not prepare statement"。这个错误通常与SQL语句执行时的问题有关。\[3\]根据官方文档的解释,@Modifying和@Transactional注解可以用于修改查询方法,而不是将其注释到域类上。@Modifying注解只在与@Query注解结合使用时才相关。这个错误可能是由于SQL语句的问题导致的。您可以检查SQL语句是否正确,并确保使用了正确的注解来执行查询。如果问题仍然存在,您可能需要进一步排查数据库连接的问题。 #### 引用[.reference_title] - *1* *3* [jpa语句:nested exception is org.hibernate.exception.GenericJDBCException: could not extract ...](https://blog.csdn.net/qq_42818496/article/details/107608978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [org.hibernate.exception.JDBCConnectionException:could not execute query原因及解决方法](https://blog.csdn.net/liuyingan/article/details/84364289)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值