//Dao
public int BoardDelete(String boardNum,Connection conn) throws Exception{
Statement stmt = null;
int cnt = 0;
try{
conn = DBConnections.getConnection();
stmt = conn.createStatement();
cnt = stmt.executeUpdate(getQueryMethod(Integer.parseInt(boardNum)));
}
catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
close.release(stmt, null); //connection 부분은 열어둠.
}
return cnt;
}
//서비스
public void deleteService(String boardNum) throws Exception{
Connection conn = null;
try{
conn = DBConnections.getConnection();
conn.setAutoCommit(false); //자동 커밋안함
int cnt = dao.BoardDelete(boardNum,conn);
if(cnt != 1){
throw new Exception("Delete Count Fail");
}
conn.commit(); //넣음.
}
catch(Exception e){
conn.rollback(); //문제 발생시 롤백함.
e.printStackTrace();
throw e;
}
finally{
if(conn != null){
conn.close(); //Connection 닫음.
}
}
}
'개발 > 자바/jsp' 카테고리의 다른 글
object replacenull (0) | 2018.09.07 |
---|---|
자바 리플렉션 (0) | 2016.08.19 |
eclipse 실행오류 could not create java virtual machine (0) | 2013.10.18 |
ResultSet 연습 (0) | 2012.03.29 |