java mysql文件编辑器_java 通过eclipse编辑器用mysql尝试 连接数据库

一、下载JDBC mysql驱动,导入jar包

我自己下载的是connector-java-6.0.6.jar,如下图所示,JDBC mysql驱动连接地址http://mvnrepository.com/artifact/mysql/mysql-connector-java/6.0.6,

069258ab8454fd7803fead6446f9824c.png

二、连接数据库

代码如下图:

01d60a9976dba84bed2c710abe773fa2.png

97ec1be6797a5544a7b11b4728a02570.png

测试类:

ea68459e8fe2b5c30240ab8d6181da49.png

然后我运行这个主方法,控制台出现如下异常:

6d34f112600a71f7d295fe7dfe8ce9ed.png

之后我将异常:

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.

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)

通过百度查找,知道我的Url地址不正确,并将其改为: private static String Url="jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";

再次运行主方法,控制台结果如下:

4aca95499721f90c3afc199e271b91e4.png

接着我再按着控制台提示将驱动Driver="com.mysql.jdbc.Driver" 改为 Driver="com.mysql.cj.jdbc.Driver"

再次运行程序,控制台出现如下警告:

5be739ef31d327d6c9fb07d697c6ad24.png

我再次将警告:Tue Nov 14 13:19:53 CST 2017 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. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

通过百度查找,最终将地址Url的值改为Url=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false,并再次运行程序,程序最终运行正常。结果如下:

e2f5e09df44b1a38aa0859864b3f486c.png

内容来源于网络如有侵权请私信删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值