MyBatis+MySql Insert操作失败解决办法
来源:互联网 发布:随机森林算法matlab 编辑:程序博客网 时间:2024/04/30 12:30
[转]MyBatis+MySql Insert操作失败解决办法
2013-5-21阅读238 评论0
初次接触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了。测试成功!
- MyBatis+MySql Insert操作失败解决办法
- MyBatis+MySql Insert操作失败解决办法
- MyBatis+MySql Insert操作失败解决办法
- MyBatis的INSERT操作
- mybatis/mysql-高级insert
- MySQL脚本insert中文失败
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- MyBatis insert操作返回主键
- window下在同一台机器上安装多个版本jdk,修改环境变量不生效问题处理办法
- 如何在 android 预制apk
- vi 编辑器常用命令
- 我爱学英语
- python之print实践
- MyBatis+MySql Insert操作失败解决办法
- Android ListView拖(滚)动到顶部或底部时出现阴影的解决方案
- How to use umdh to check Windows memory leak
- 20个最佳的Java集合框架面试题目
- Python xlrd、xlwt、xlutils修改Excel文件
- 全文索引 Lucene初探
- cots 常见问题解答
- Python中map()函数浅析
- 诗意回文