```java
//剩下的就是用户的增删改了,大致思路都是一样的,但是都需要处理事务!
//service层的举例:
public boolean add(User user) {
boolean flag = false;
Connection connection = null;
try {
connection = BaseDao.getConnection();
connection.setAutoCommit(false); //开启JDBC事务管理
int updateRows = userDao.add(connection,user);
connection.commit();
if(updateRows > 0){
flag = true;
System.out.println("add success!");
}else{
System.out.println("add failed!");
}
} catch (Exception e) {
e.printStackTrace();
try {
//如果执行出错就回滚
connection.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
}finally{
//在service层进行connection连接的关闭
BaseDao.closeResource(connection, null, null);
}
return flag;
}
标签:false,updateRows,管理,实现,flag,add,用户,connection,null
From: https://www.cnblogs.com/hytip/p/18182463