MyBatis+MySql Insert操作失败解决办法
2013-05-21 00:27
337 查看
初次接触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了。测试成功!
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操作失败解决办法
- 关于DOS界面net start MySQL 启动失败的解决办法
- Yosemite下使用 XAMPP 时 MySql 启动失败解决办法
- php操作csv文件导入mysql时中文乱码的解决办法
- mysql在CentOS7.0服务启动失败的解决办法
- mysql导入数据时一个insert过大导致Mysql server has gone way,解决办法
- 向 mysql 插入insert时 汉字 Incorrect string value 解决办法
- MySQL 数据库重装失败最后一步无法启动server的解决办法
- MYSQL启动失败,提示Can't find file: './mysql/host.frm'解决办法
- 重装MySQL失败的终极解决办法!
- mysql-workbench工具update(更新)失败的解决办法
- ambari安装hive以mysql作为元数据存储建表失败的解决办法
- Java操作mysql数据库,提示登录失败解决办法
- Oracle+Mybatis的foreach insert批量插入报错的快速解决办法
- 重装MySQL失败的终极解决办法!
- SSM框架day02-MyBatis——031、033——对单表的CURD操作-复合条件查询-遗留问题及解决办法
- AutoIT操作Mysql,写入数据,不支持中文的解决办法。
- Mysql登录失败错误(10061)解决办法