2013-07-27 87 views
10

我想在我的Play Framework 2.0應用程序的application.conf文件中設置autoReconnect = true mysql連接屬性。但它給我以下錯誤:如何在Play Framework配置文件中爲mysql db url設置autoReconnect屬性?

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:[email protected]/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. 

我也嘗試設置這些戲DB參數如下(https://groups.google.com/forum/#!topic/play-framework/KzvbZ61j9Eo)中提到,以解決這方面的問題,但它沒有解決問題。

idleConnectionTestPeriod=10 
testConnectionOnCheckin=true 

任何指導解決這個問題將不勝感激。

謝謝。

+0

做了這項工作?我添加了?autoReconnect = true的jdbc url,但當我等待太久stil得到相同的錯誤,它不會自動重新連接 – Gavriel

回答

9

明顯的事情是追加 '?了useUnicode = YES' 到您的URI,所以你最終

mysql://db_user:[email protected]/mydb?autoReconnect=true?useUnicode=yes 

解析這會給你,對於autoReconnect的值爲真的嗎?了useUnicode = YES

挖了一下,也許你的連接池或數據抽象層正在這樣做。

+2

謝謝,我有編碼問題廣告'jdbc:mysql://127.0.0.1:3306/Mysql?relaxAutoCommit = " true "'在我的文件中。剛剛刪除它,它的作品。 – MokaT

5

你有2個連接參數,連接它們與&而不是? :

mysql://db_user:[email protected]/mydb?autoReconnect=true&useUnicode=yes 
相關問題