赌博技巧 jdbcUtil工具类
private static DataSource ds = new ComboPooledDataSource();
private static Connection connection;
public static DataSource getDataSource(){
return ds;
}
//获取连接
public static Connection getConnection(){
if(connection==null){
try {
return ds.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return connection;
}
//启动事务
public static void start() throws SQLException{
if(connection!=null){
throw new SQLException("有进行中的事务,请等待当前事务结束");
}
connection = ds.getConnection();
connection.setAutoCommit(false);
}
//提交事务
public static void end() throws SQLException{
if(connection==null){
System.out.println("当前未建立连接赌博技巧,不能提交事务");
}
connection.commit();
connection.close();
connection=null;
}
//回滚事务
public static void rollBack() throws SQLException{
if(connection==null){
System.out.println("当前未建立连接赌博技巧,不能回滚事务");
}
connection.rollback();
connection.close();
connection=null;
}
}