1.在進行jdbc與mysql連接的時候應注意,加載驅動的方式根據MySQL版本內容來說 有變化
5.7版本之前:
String driver= "com.mysql.jdbc.Driver"; String url="jdbc:mysql://localhost:3306/數據庫名字"; String user="數據庫用戶名"; String password="數據庫密碼";
5.7版本之后:
String driver= "com.mysql.cj.jdbc.Driver"; String url="jdbc:mysql://localhost:3306/dbnamel"; String user="數據庫用戶名"; String password="數據庫密碼";
注意標紅字體,加載驅動語句並不一樣
2. MySQL8.0版本之后,連接數據庫會有時區不一致的錯誤
錯誤信息:Error querying database. Cause: 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.
此時的解決方法是:
在控制台進入MySQL
輸入以下命令:
show variables like '%time_zone%';
查看時區信息
然后輸入
set global time_zone='+8:00';
輸入exit退出,然后重新登入數據庫並輸入命令:
show variables like '%time_zone%';
此時時區問題就已經解決好了