The use of MySQL8, in the integration of the SSM framework, with the MyBatis reverse engineering generated code testing, the implementation of the database query before the normal, but when the query, the card master did not respond, set the log, try catch, and so also do not error, the page has been turned, Before the MyBatis automatically generated code is normal, and then in the test class, using connection for connection testing and querying the database, but also can normally query to the data:
Connection conn = null;
try {
String userName = "root";
String password = "[email protected]";
String jdbcurl = "Jdbc:mysql://localhost:3306/test?useunicode=true&usessl=false&autoreconnect=true &characterencoding=utf-8 ";
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
conn = drivermanager.getconnection (Jdbcurl, userName, password);
String sql = "SELECT * from Tb_user";
PreparedStatement pstmt = conn.preparestatement (sql);
ResultSet rs = Pstmt.executequery ();
String result = "";
while (Rs.next ()) {
int id = rs.getint ("id");
String name = rs.getstring ("username");
String status = Rs.getstring ("Phone");
Result + = id + "\ t" + name + "\ T" + status + "\ n";
}
System.out.println (result);
Instead of reverse engineering:
userexample example = new Userexample ();
Userexample.criteria Criteria = Example.createcriteria ();
Criteria.andidequalto (USERID);
list<user> list = Usermapper.selectbyexample (example);//This step in will not come out ...
After confirming that the SSM other configuration files have not found a problem, and then think is not the MySQL8 version of the problem, after all, before using Navicat connection MySql8 also has several problems, so Upgrade the Mysql-connect-java version from 5.1.6 to 8.0.11, and modify the Db.properties file :
Note that there are no spaces in the file
jdbc.driver=Com.mysql.cj.jdbc.Driver
Jdbc.url=jdbc:mysql://localhost:3306/test? usessl=false&useUnicode=true&characterEncoding=UTF8&servertimezone=gmt
Jdbc.username=root
[Email protected]
After restarting the project, everything is finally normal ...
MyBatis connection MySQL8 problems that occur