mybatis连接MySQL8出现的问题解决方法
作者:pp153 时间:2024-01-22 08:27:59
使用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
重启项目后,一切终于正常了。。。。。。
来源:http://www.cnblogs.com/pp153/p/9220356.html
标签:mybatis,MySQL8,连接
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python openpyxl模块实现excel读写操作
2023-07-17 20:15:25
![](https://img.aspxhome.com/file/2023/6/84876_0s.png)
Python 递归式实现二叉树前序,中序,后序遍历
2022-09-22 17:38:32
![](https://img.aspxhome.com/file/2023/7/66777_0s.png)
Python 3中print函数的使用方法总结
2021-12-21 00:37:18
用CSS设置表格Table的细边框的比较好用的方法
2010-09-06 14:58:00
Python新手如何进行闭包时绑定变量操作
2021-05-01 15:23:55
FrontPage XP设计教程1——站点初建与管理
2008-10-11 12:13:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017121637930.jpg)
用ASP实现远程批量文件改名
2007-09-12 12:23:00
未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
2023-07-01 00:38:21
python中注释用法简单示例
2022-10-24 05:04:09
![](https://img.aspxhome.com/file/2023/8/111918_0s.png)
python机器人行走步数问题的解决
2023-12-24 23:26:05
python中Genarator函数用法分析
2023-01-03 16:50:52
windows、linux下打包Python3程序详细方法
2023-09-30 22:06:53
![](https://img.aspxhome.com/file/2023/0/62930_0s.png)
Golang开发库的集合及作用说明
2024-02-01 08:03:24
Python单体模式的几种常见实现方法详解
2021-02-24 04:45:51
Django MEDIA的配置及用法详解
2022-12-12 01:35:41
![](https://img.aspxhome.com/file/2023/6/72866_0s.png)
Python实现二维数组输出为图片
2022-10-07 21:49:55
asp如何直接调用Excel数据?
2010-06-28 18:26:00
Python对切片命名的实现方法
2023-09-30 09:43:15
Python2和Python3的共存和切换使用
2022-12-26 13:05:20
![](https://img.aspxhome.com/file/2023/7/104967_0s.png)
python之消除前缀重命名的方法
2021-12-25 09:28:42