MySQL连接超时

MySQL连接超时

问题描述:

我正在apache tomcat服务器上运行程序,该程序应该是永久性的,但每天早上(客户端部分在晚上无法访问)我收到MySQL服务器关闭的错误消息(在apache tomcat控制台中)。那么有什么方法可以防止这种情况发生?
提前致谢!

I'm running program at apache tomcat server, that should be on permanently, but every morning(the client part isn't accessible at night) i receive error message (in apache tomcat console) that MySQL server is off. So is there any way to prevent this? Thanks in advance!

是的,我遇到了同样的问题。尝试将validationQuery添加到您的DataSource。

Yes, I have had the same problem. Try to add a validationQuery to your DataSource.

以下是我定义的方法:

<Resource auth="Container"
          type="javax.sql.DataSource"
          name="jdbc/gporder"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost/mydb"
          maxActive="10"
          maxIdle="5"
          validationQuery="SELECT 1"
          testOnBorrow="true"
          testWhileIdle="true"
          timeBetweenEvictionRunsMillis="10000"
          minEvictableIdleTimeMillis="60000"
          username="..." password="..."/>