JDBC connection database error analysis

 

1. When registering the driver, the old version is written as:

 

//注册驱动 Class.forName("com.mysql.jdbc.Driver");

 

But in the new version this will report an error,

The prompt message indicates that the database driver com.mysql.jdbc.Driver' has been deprecated and the new driver com.mysql.cj.jdbc.Driver' should be used

So we need to rewrite it as:

 

Class.forName("com.mysql.cj.jdbc.Driver");

 

 

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

 

The error is this line:

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/monkey1024", "root", "semiconductor");

 

It can be seen from the error message: it is impossible to check whether the table has been displayed using metadata. When the table is created, it cannot be connected normally. Looking down, The server time zone value, about this version, is the most common in the new version of the Mysql service, because The environment I use is the latest MySLQ community version. The time zone used in the new version of the database is different from the local time zone. The standard time zone uses the time from the first year of Unix as the starting point to the current time. The international standard loses and the local difference is 8 hours.

That is to say, the difference between the local time zone and the standard time zone is 8 hours.

 

solution:

 

Add jdbc:mysql://localhost:3306/Database_Name after

?serverTimezone=GMT%2B8

 

That is:

//获取连接 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/monkey1024?serverTimezone=GMT%2B8", "root", "semiconductor");

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326390479&siteId=291194637