错误:
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"