DAO事物函数模版1:
public void OrderFinsByPage(){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null; try { conn = DBUtils.getConnection();
//事务开始
conn.setAutoCommit(false);
//业务逻辑 conn.commit(); } catch (Exception e) {
try {
conn.rollback();
} catch (SQLException sqkex) {
// TODO Auto-generated catch block
sqkex.printStackTrace();
}
e.printStackTrace();
}finally {
try {
conn.setAutoCommit(true);
if(conn !=null) conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }
进阶篇:
封装成为BASEDAO,方法详见JDBC项目框架!