标签:mys ons either creates error char jdb epo 导入jar包
注:本人学的是Oracle,用mysql连接数据库是一次尝试。
一、下载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,并再次运行程序,程序最终运行正常。结果如下:
java 通过eclipse编辑器用mysql尝试 连接数据库
标签:mys ons either creates error char jdb epo 导入jar包
原文地址:http://www.cnblogs.com/sxx1993/p/7832085.html