update autcommit and remove rollback to storage data as much as possible

This commit is contained in:
clevertension 2017-10-18 09:48:38 +08:00
parent f1423649e6
commit 80da64e4ae
2 changed files with 2 additions and 9 deletions

View File

@ -105,14 +105,13 @@ public class H2Client implements Client {
boolean flag;
Connection conn = getConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
conn.setAutoCommit(false);
conn.setAutoCommit(true);
if (params != null) {
for (int i = 0; i < params.length; i++) {
statement.setObject(i + 1, params[i]);
}
}
flag = statement.execute();
conn.commit();
} catch (SQLException e) {
throw new H2ClientException(e.getMessage(), e);
}

View File

@ -45,7 +45,7 @@ public class BatchH2DAO extends H2DAO implements IBatchDAO {
final Map<String, PreparedStatement> batchSqls = new HashMap<>();
try {
conn = getClient().getConnection();
conn.setAutoCommit(false);
conn.setAutoCommit(true);
PreparedStatement ps;
for (Object entity : batchCollection) {
H2SqlEntity e = getH2SqlEntity(entity);
@ -70,14 +70,8 @@ public class BatchH2DAO extends H2DAO implements IBatchDAO {
for (String k : batchSqls.keySet()) {
batchSqls.get(k).executeBatch();
}
conn.commit();
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
try {
conn.rollback();
} catch (SQLException e1) {
logger.error(e.getMessage(), e1);
}
}
batchSqls.clear();
}