1. 程式人生 > >java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼

使用Idea做jdbc的時候用了最新的mysql-connector-java-8.0.11庫發現編碼沒有異常但是執行時出現了兩個異常,如下

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.

意思是 mysqljdbc . driver被棄用了新的驅動類是“com.mysql.cjdbc.driver”。驅動程式通過SPI自動註冊,而手動載入類通常是不必要的,解決方案如下:

把com.mysql.jdbc.Driver 改為com.mysql.cj.jdbc.Driver 即可

第二個異常:

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time

第二個異常是時區的錯誤,因此只你需要設定為你當前系統時區即可,解決方案如下:

static final  String DB_URL="jdbc:mysql://localhost:3306/csm"+"?serverTimezone=GMT%2B8";
 
//加上?serverTimezone=GMT%2B8" 即可  GMT%2B8代表: 東八區
 
//GMT%2B8代表: 東八區