mybatis連接MySQL8出現的問題


使用MySQL8,在整合ssm框架,用mybatis逆向工程生成的代碼測試時,執行到數據庫查詢前均正常,但進行查詢時,便卡主沒有反應了,設置了日志、try catch等也不報錯,頁面就在那一直轉,之前mybatis自動生成代碼都是正常的,然后在測試類中,使用Connection進行連接測試並查詢數據庫,也是能夠正常查詢到數據的:

Connection conn = null;
try {
String userName = "root";
String password = "111@tesT";
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);

而逆向工程的卻不行:
UserExample example = new UserExample();
UserExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(userId);
List<User> list = userMapper.selectByExample(example);//這一步進去后就出不來了。。。

經過確認ssm其他配置文件都沒有發現有問題,然后就想是不是自己用的MySQL8版本的問題,畢竟之前使用Navicat連接MySql8也是出了好幾個問題,於是便將mysql-connect-java版本由5.1.6升級為8.0.11,並修改了db.properties文件
#數據庫連接 注意 文件內不要留有空格
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
jdbc.password=111@tesT

重啟項目后,一切終於正常了。。。。。。



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM