如何判断数据库语句是否能正常执行
思路是执行一次再回滚,但就是回滚不了。有什么更好的思路也提供一下,最好有示例代码,谢谢!
public static void sqlRight(Connection conn, String sql) throws Exception{
conn.setAutoCommit(false);
PreparedStatement ps = DBCommon.prepare(conn, sql);
try {
ps.executeUpdate();
} catch (SQLException e) {
throw e;
}
finally{
conn.rollback();
conn.setAutoCommit(true);
DBCommon.close(ps);
DBCommon.close(conn);
}
}