我的应用程序有以下代码:
Connection connection = DriverManager.getConnection(url, userName, password);
connection.setAutoCommit(false);
try {
Statement statement = connection.createStatement();
try {
statement.executeUpdate("TRUNCATE mytable");
} finally {
statement.close();
}
connection.commit();
connection.setAutoCommit(true);
statement = connection.createStatement();
try {
statement.executeUpdate("VACUUM mytable");
} finally {
statement.close();
}
connection.setAutoCommit(false);
connection.commit();
} finally {
connection.close();
}
statement.executeUpdate("VACUUM mytable");
因VACUUM cannot run inside a transaction block
而失败。
我必须遗漏一些概念,因为我认为将自动提交设置为true
会删除事务上下文(TRUNCATE
所需)。显然它没有。那么如何摆脱事务上下文并成功执行我的VACUUM?我应该如何编写代码以使其没有此事务上下文?