【发布时间】:2016-12-20 19:22:39
【问题描述】:
我的 Web 应用程序现在运行良好,并将数据保存到 mysql 数据库。只有我无法理解连接的一件事是,它会在一段时间后断开数据库上的连接,我需要继续停止并重新启动 Tomcat 以保持与应用程序的连接处于活动状态。 我需要在 tomcat 网络服务器或 mysql 数据库中设置任何会话超时吗?
下面是我在 spring boot 中的 application.properties。
debug=true
spring.datasource.url=jdbc:mysql://localhost/database
spring.datasource.username=username
spring.datasource.password=pass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=DEBUG
Below is the exception:
Exception: org.springframework.dao.DataAccessResourceFailureException: could not prepare statement; nested exception is org.hibernate.exception.JDBCConnectionException: could not prepare statement
感谢您的帮助。
唐纳德
【问题讨论】:
-
请发布您的 jdbc 连接 url。一定是这样的
url="jdbc:mysql://localhost:3306/hposg -
请查看this是否有帮助
-
spring.datasource.testOnBorrow=true spring.datasource.validationQuery=SELECT 1
标签: mysql spring hibernate tomcat spring-boot