You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
### 事务提交
|
|
```aidl
|
|
Connection conn = null;
|
|
try {
|
|
conn = DbKit.getConfig().getDataSource().getConnection();
|
|
DbKit.getConfig().setThreadLocalConnection(conn);
|
|
// 自动提交表成fasle:手动提交
|
|
conn.setAutoCommit(false);
|
|
for (Record r1 : l2) {
|
|
int id = r1.getInt("id");
|
|
String step_code = r1.getStr("step_code");
|
|
sql = "update t_gtzz_sy_laststep set step_name=?,days_limit=? where id=?";
|
|
Record r = _map.get(step_code);
|
|
Db.update(sql, r.getStr("step_name"), r.getStr("days_limit"), id);
|
|
}
|
|
conn.commit();
|
|
} catch (SQLException e) {
|
|
try {
|
|
if (null != conn) conn.rollback();
|
|
} catch (SQLException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
throw new ActiveRecordException(e);
|
|
} finally {
|
|
try {
|
|
if (null != conn) conn.close();
|
|
} catch (Exception e2) {
|
|
e2.printStackTrace();
|
|
} finally {
|
|
DbKit.getConfig().removeThreadLocalConnection();
|
|
}
|
|
}
|
|
```
|
|
|
|
### Jfinal批量提交带参数的例子
|
|
```aidl
|
|
//Jfinal批量提交带参数的例子
|
|
sql = "update t_gtzz_sy_laststep set step_name=?,days_limit=? where id=?";
|
|
Object[][] para = new Object[l2.size()][3];
|
|
int cnt = 0;
|
|
for (Record r1 : l2) {
|
|
int id = r1.getInt("id");
|
|
String step_code = r1.getStr("step_code");
|
|
Record r = _map.get(step_code);
|
|
para[cnt][0] = r.getStr("step_name");
|
|
para[cnt][1] = r.getStr("days_limit");
|
|
para[cnt++][2] = id;
|
|
}
|
|
Db.batch(sql, para, 1000);
|
|
```
|
|
|
|
### 记录执行时间
|
|
```aidl
|
|
|
|
long startTime=System.currentTimeMillis();
|
|
|
|
...
|
|
|
|
long endTime=System.currentTimeMillis();
|
|
long total = endTime - startTime;
|
|
System.out.println("耗时时间" + total +"ms");
|
|
```
|
|
|