实现程序还原数据库时的批量操作,数据库采用的是SQLite,使用事物时报错,程序代码
/** * 开启事物的批量任务 * @param tableName * @param sqlColumns * @param sqlValues * @param lists */ public static void batchTask(String tableName, String sqlColumns, String sqlValues, List<Record> lists){ Db.tx(new IAtom() { @Override public boolean run() throws SQLException { try { String delSql = "delete from " + tableName; if(tableName.equals("sys_config")){ delSql = "delete from sys_config where item not in("+SysConfig.remainItems+")"; } Db.update(delSql); String sql = "insert into " + tableName + "(" + sqlColumns + ") values (" + sqlValues + ")"; Db.batch(sql, sqlColumns, lists, 100); } catch (Exception e) { e.printStackTrace(); return false; } return true; } }); }
java.sql.SQLException: database in auto-commit mode at org.sqlite.Conn.rollback(Conn.java:350) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)
2016-03-17 10:57:05.055 ERROR com.ddt.service.platform.BackupService - com.ddt.service.platform.BackupService com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: SQLite supports only TRANSACTION_SERIALIZABLE and TRANSACTION_READ_UNCOMMITTED. at com.jfinal.plugin.activerecord.DbPro.tx(DbPro.java:655) ~[jfinal-1.9-bin-with-src.jar:na] at com.jfinal.plugin.activerecord.DbPro.tx(DbPro.java:680) ~[jfinal-1.9-bin-with-src.jar:na] at com.jfinal.plugin.activerecord.Db.tx(Db.java:440) ~[jfinal-1.9-bin-with-src.jar:na]
异常抛出的问题?catch了异常,导致无法抛出,事务无法执行?
猜一下。。
跟踪了以下代码在这里catch里异常,不明白怎么回事:Dbpro.class第642行conn.setTransactionIsolation(transactionLevel);catch(Throwablet){……}这些升级到jfinal2.2设置隔离级别就可以解决,Db.tx(Connection.TRANSACTION_SERIALIZABLE,newIAtom(){
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。