发表于: 2017-06-05 01:00:35

2 1740


今天完成的主要事情:

1、尝试在maven项目中用JDBC链接mysql数据库

首先,创建maven项目

添加mysql数据库驱动依赖(根据网络上搜出来的结果,普遍都是mysql-connector-java-xxx-bin.jar)

这是pom.xml包

接下来,在main中建立.java文件,编写类,以下是部分连接数据库的代码

问题来了:始终显示的是以下错误,找不到数据库驱动,在网上找了许多

从网络上查询原因,各种方法都尝试了遍,依然不行,然后不死心,用普通java工程再尝试一遍


这是项目结构和java代码,这次运行后提示的错误是:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

连接数据库...

Mon Jun 05 00:50:03 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.

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)

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

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

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

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

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:69)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1606)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at JdbcMysql.main(JdbcMysql.java:22)

Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: 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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)

at com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118)

at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:293)

at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2399)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1739)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1596)

... 6 more

Goodbye!


根据前两行的提示,将代码中的“com.mysql.jdbc.Driver”改成了"com.mysql.cj.jdbc.Driver",再次运行,依然报同样的错误。所以在这里希望师兄指点。


返回列表 返回列表
评论

    分享到