用java通过jdbc连接mysql数据库总结

参网站:1、https://www.cnblogs.com/centor/p/6142775.html

              2、https://blog.csdn.net/huwentao0305/article/details/53378755

              3、https://blog.csdn.net/u012660464/article/details/52292099

首先参考上面的网站下载:

MySQL连接驱动:mysql-connector-java-8.0.11。

根据参考网站教程在项目中加入连接驱动包。

然后复制网站1的代码运行后出现错误。

Loading class `com.mysql.jdbc.Driver'. This is deprecated. 和

WARN: Establishing SSL connection without server's identity verification is not recommended.

According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.

和  The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone.

网上查了查,

第一个错误:这个错误比较好解决,把com.mysql.jdbc.Driver修改为com.mysql.cj.jdbc.Driver。

第二个错误:是当前版本的MySQL要求使用SSL,

第三个错误:需要在Url后面添加一个参数:

所以把:String url = "jdbc:mysql://localhost:3306/user_password";  做出如下修改即可:

String url = "jdbc:mysql://localhost:3306/user_password?serverTimezone=UTC&useSSL=false ";

知识点补充:

连接器驱动参考文档:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference.html

http://elf8848.iteye.com/blog/1684414

猜你喜欢

转载自www.cnblogs.com/lqwh/p/9075855.html