3334353637383940
public Connection getConnection(){ try{ return DBManager.getConnection(); }catch(SQLException e){ throw new DBException(e); } }
7071727374757677
DatabaseMetaData mdm = conn.getMetaData(); log.info("Connected to " + mdm.getDatabaseProductName() + " " + mdm.getDatabaseProductVersion()); closeConnection(); } catch (Exception e) { throw new DBException(e); } }
7980818283848586
/** 开启事务 */ public static void beginTransaction() throws DaoException{ try { getConnection().setAutoCommit(false); //把事务提交方式改为手工提交 } catch (SQLException e) { throw new DBException("开户事务时出现异常"); } }
88899091929394959697
/** 提交事务并关闭连接 */ public static void commitAndClose() throws DaoException{ try { getConnection().commit(); //提交事务 } catch (SQLException e) { throw new DBException("提交事务时出现异常"); }finally{ closeConnection(); } }
99100101102103104105106107108
/** 回滚并关闭连接 */ public static void rollbackAndClose()throws DaoException{ try { getConnection().rollback(); } catch (SQLException e) { throw new DBException("回滚事务时出现异常",e); }finally{ closeConnection(); } }