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

2018-06-18 00:32:29来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

 

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

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

二、连接数据库

代码如下图:

测试类:

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

之后我将异常:

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";

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

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

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

我再次将警告: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,并再次运行程序,程序最终运行正常。结果如下:

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:mysql数据库事务详细剖析

下一篇:mysql 基本常用语句