mysql - 如何在 Play Framework 配置文件中为 mysql db url 设置 autoReconnect 属性?

标签 mysql jdbc playframework-2.0

我正在尝试在我的 Play Framework 2.0 应用程序的 application.conf 文件中设置 autoReconnect=true mysql 连接属性。但它给了我以下错误:

Caused by: java.sql.SQLException: The connection property 'autoReconnect' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true?useUnicode=yes' is not in this set.

这是我在 application.conf 文件中的连接字符串:

db.default.url="mysql://db_user:db_user@localhost/mydb?autoReconnect=true"

我正在尝试设置此连接参数,因为我的应用程序在长时间空闲后出现此错误:

[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08S01
[error] application - Failed to login the user : guest
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully  
received from the server was 153,398,761 milliseconds ago.  
The last packet sent successfully to the server was 153,398,762 milliseconds ago. is longer than the server configured value of 'wait_timeout'. 
You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

我还尝试设置这些 Play 数据库参数来解决此连接问题,如此处所述 (https://groups.google.com/forum/#!topic/play-framework/KzvbZ61j9Eo) 但它没有解决问题。

idleConnectionTestPeriod=10
testConnectionOnCheckin=true

任何解决此问题的指导将不胜感激。

谢谢。

最佳答案

显然有些东西在你的 URI 上附加了 '?useUnicode=yes',所以你最终得到了

mysql://db_user:db_user@localhost/mydb?autoReconnect=true&useUnicode=yes

解析这会让您知道 autoReconnect 的值为 true?useUnicode=yes

深入挖掘一下,也许您的连接池或数据抽象层正在这样做。

关于mysql - 如何在 Play Framework 配置文件中为 mysql db url 设置 autoReconnect 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17901034/

相关文章:

php - 显示所有行并通过提交更新所有行

mysql导入具有巨大blob表字段的大文件

java - 在 GlassFish 上创建 JDBC 连接池仅接受 Oracle 的一个操作数

java - ojdbc8 jar 未加载到 Tomcat8 中

java - 在 Play Framework URL 中传递 MongoDB ObjectId

mysql - 尝试将数据插入 MySQL 数据库表时发生 Python 错误

php - Codeigniter:使用数据库存储多个用户的数据库名称

java - jdbc 连接错误 : not associated with a managed connection

hibernate - 如何使用 JPA 插件获取 Play Framework 2 中的 org.hibernate.cfg.Configuration

scala play framework 2.2.6编码问题