📄 transmanager.java
字号:
package llm.pool.relation;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
/**
* TransManager : 数据库事务管理
*/
public final class TransManager {
// public static final int ORACLE = 0;
public static final int SYBASE = 1;
public TransManager() {
}
/**
* 事务开始执行
* @param conn Connection
* @param dbType int
* @throws SQLException
*/
public static void beginTrans(Connection conn, int dbType) throws
SQLException {
if (dbType == SYBASE) {
Statement stmt = conn.createStatement();
stmt.execute("begin tran");
stmt.close();
}
else
conn.setAutoCommit(false);
}
/**
* 事务完成后提交
* @param conn Connection
* @param dbType int
* @throws SQLException
*/
public static void commitTrans(Connection conn, int dbType) throws
SQLException {
if (dbType == SYBASE) {
Statement stmt = conn.createStatement();
stmt.execute("commit tran");
stmt.close();
}
else
conn.commit();
}
/**
* 事务失败后回滚
* @param conn Connection
* @param dbType int
* @throws SQLException
*/
public static void rollbackTrans(Connection conn, int dbType) throws
SQLException {
if (dbType == SYBASE) {
Statement stmt = conn.createStatement();
stmt.execute("rollback tran");
stmt.close();
}
else
conn.rollback();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -