這兩個錯誤都是因為版本的更新導致的;
錯誤代碼:
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";
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/121240.html
標籤:MySQL
上一篇:mybatis批量新增報錯 BadSqlGrammarException
下一篇:MySQL8.0+常用命令
