MySql :Could not create connection to database server.
錯誤:
Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException:Error querying database. Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
The error may exist in cn/action/dao/UserDao.xml
The error may involve cn.action.dao.UserDao.findList
The error occurred while executing a query
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
at cn.action.test01.TestSelectList.main(TestSelectList.java:29)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
原因:
MySql8.0應用低版本jar包,產生錯誤
解決:
1.下載高版本jar包
下載后解壓:
2.更改驅動名
以前:com.mysql.jdbc.Driver
更改后:com.mysql.cj.jdbc.Driver
3.刪除原來的驅動包
項目上右鍵->Build Path->Configure Build Path->Libraries中帶錯誤的jar包remove
4.由于版本時區不同,要在數據庫后加上“?serverTimezone=UTC"
總結
以上是生活随笔為你收集整理的MySql :Could not create connection to database server.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 节食减肥期间老是口渴
- 下一篇: IDEA如何在包下建立子包