Public class DbUtil {
Public static final String URL="JDBC: mysql://*. *. *. * : */test? UseUnicode=true& CharacterEncoding=utf-8 & amp; UseJDBCCompliantTimezoneShift=true& UseLegacyDatetimeCode=false& ServerTimezone=UTC ";
Public static final String USER="*";
Public static final String PASSWORD="*";
Public static void main (String [] args) throws the Exception {
Class.forname (". Com. Mysql. Cj. JDBC Driver ");
The Connection conn=DriverManager. GetConnection (URL, USER, PASSWORD);
The Statement STMT=conn. CreateStatement ();
The ResultSet rs=STMT. ExecuteQuery (" SELECT * FROM the user ");
While (rs), next ()) {
System. The out. Println (rs. Get string (" id ") + "name:" + rs. Get int (" name "));
}
}
}
Pom
<? The XML version="1.0" encoding="utf-8"?>
Xsi: schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" & gt;
The database version of
Mysql> Select the version ();
+ -- -- -- -- -- -- -- -- -- -- - +
(1) | | version
+ -- -- -- -- -- -- -- -- -- -- - +
| 8.0.20 |
+ -- -- -- -- -- -- -- -- -- -- - +
1 row in the set (0.37 SEC)
Mysql>
Run incredibly error
The Exception in the thread "main" Java. SQL. SQLException: Unknown system variable 'query_cache_size'
At com. Mysql. Cj. JDBC. Exceptions. SQLError. CreateSQLException (SQLError. Java: 129)
At com. Mysql. Cj. JDBC. Exceptions. SQLError. CreateSQLException (SQLError. Java: 97)
CodePudding user response:
1. Mysql - connecter - Java version is too low, is obviously database drivers don't correspond with the database version2. The query cache is removed after Mysql 8.0
CodePudding user response:
The