JDBC连接时出现的两个错误
Posted 20glym
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JDBC连接时出现的两个错误相关的知识,希望对你有一定的参考价值。
这两个错误都是因为版本的更新导致的;
错误代码:
package FirstTest; import java.sql.*; public class FirstJDBC { public static void main(String[] args) throws SQLException { try { //加载驱动类 Class.forName("com.mysql.jdbc.Driver"); //建立连接 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test.jdbc","root","123456"); System.out.println(con); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
错误一:
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.
如错误信息所示:在加载类时`com.mysql.jdbc.Driver‘已过时,应改为`com.mysql.cj.jdbc.Driver‘
错误二:
Exception in thread "main" 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.
该错误为由系统时间错误引起,只需要在访问数据库时在Url后面加上以下的语句即可:
OLD_URL = "jdbc:mysql://localhost:3306/test.jdbc";
NEW_URL = "jdbc:mysql://localhost:3306/test.jdbc?serverTimezone=GMT%2B8";
以上是关于JDBC连接时出现的两个错误的主要内容,如果未能解决你的问题,请参考以下文章
MyBatis+Oracle时出现的错误: Method oracle/jdbc/driver/OracleResultSetImpl.isClosed()Z is abstract