MyBatis+MySql Insert操作失败解决办法
2015-12-10 17:28
483 查看
初次接触MyBatis,遇到数据库使用MySql时Insert失败的问题(select时正常)。在日志中复制SQL语句是可以执行的,不知道什么原因,怀疑是事务问题。
google后看到一哥们也遇到了此问题,不过他找到了一个解决办法,下面是他原话(他的症状和我遇到的一样,不过我不知道哪里有问题,他知道是数据库引擎的问题~):
The Engine in MySql is innoDB. Which retrieves the data from the table successfully, but i cant insert the data, i cant get any exception or error.
which works fine in MyISAM type.
有他这段信息就好办了,下面是我的2个解决办法:
方法1:把数据库表都改成了MyISAM,果然数据插入成功了!
方法2:数据库引擎不变
搜了一些资料,看到说 innoDB是自动提交事务的,而MyBatis管理事务时默认不提交。
资料地址:
http://tech.b3log.org/articles/2012/05/29/1338271764507.html讲述innoDB和MyISAM的区别及MyBatis管理事务时默认不提交。
http://sishuok.com/forum/blogPost/list/3897.html有openSession方法调用的
openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit)方法的原型。
看到openSession有autoCommit这个参数,那这样调用(openSession(true))就OK了。测试成功!
转载:http://m.blog.csdn.net/blog/jinhuawu/8953144
google后看到一哥们也遇到了此问题,不过他找到了一个解决办法,下面是他原话(他的症状和我遇到的一样,不过我不知道哪里有问题,他知道是数据库引擎的问题~):
The Engine in MySql is innoDB. Which retrieves the data from the table successfully, but i cant insert the data, i cant get any exception or error.
which works fine in MyISAM type.
有他这段信息就好办了,下面是我的2个解决办法:
方法1:把数据库表都改成了MyISAM,果然数据插入成功了!
方法2:数据库引擎不变
搜了一些资料,看到说 innoDB是自动提交事务的,而MyBatis管理事务时默认不提交。
资料地址:
http://tech.b3log.org/articles/2012/05/29/1338271764507.html讲述innoDB和MyISAM的区别及MyBatis管理事务时默认不提交。
http://sishuok.com/forum/blogPost/list/3897.html有openSession方法调用的
openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit)方法的原型。
看到openSession有autoCommit这个参数,那这样调用(openSession(true))就OK了。测试成功!
转载:http://m.blog.csdn.net/blog/jinhuawu/8953144
相关文章推荐
- MySQL数据类型
- 关于mysql的服务端参数max_allowed_packet
- MySQL
- 10014---MySQL--管理(用户设置,Show命令)
- yum mysql
- mysql中使用bit_count来统计使用
- Windows7下如何在命令行使用MySQL
- mysql 安装
- mysql主主复制
- Ubuntu下安装mysql
- Kettle连接MySQL失败原因
- MySQL慢查询日志
- MySQL存储过程调试工具
- 解决mysql5数据库连接超时问题
- 3分钟安装一个MySQL
- 10013---MySQL--简介,安装
- MySQL服务器的连接数
- MySQL安装自带的测试数据库
- mysql存储过程
- mysql建表一个timestamp类型字段会默认为当前时间,TIMESTAMP与DATETIME区别