MyBatis connection MySQL8 problems that occur

Source: Internet
Author: User
Tags try catch

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.