项目JDBC连接数据库二连坑(jar包版本问题以及时区问题)

1.jar包版本不对

教学大多用的是 mysql-connector-java-5.0.X.jar
而自己的数据库大多用的是 mysql-connector-java-8.0.X.jar,此类问题下载并导入新的jar包即可在这里插入图片描述
报错如下:
###Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
###The error may exist in dao/IUserDao.xml
###The error may involve dao.IUserDao.findAll
###The error occurred while executing a query
###Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
问题:在这里插入图片描述

2.数据库连接的时区问题

报错如下:
###Error querying database. Cause: java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
###The error may exist in dao/IUserDao.xml
###The error may involve dao.IUserDao.findAll
###The error occurred while executing a query
###Cause: java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
在这里插入图片描述
说明这样的配置有问题:
在这里插入图片描述
应该改成: ……?serverTimezone=UTC 加上UTC
在这里插入图片描述
运行成功:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq374461948/article/details/105893663