관리 메뉴

moozi

5/26 deleteBoard 부모글삭제시 댓글삭제. 트랜잭션처리 본문

TIS_2021/인공지능2021_1기

5/26 deleteBoard 부모글삭제시 댓글삭제. 트랜잭션처리

moozi 2021. 5. 26. 15:03
public void deleteBoard(String num) {
		String sql="delete board where num=?";
		String sql2="delete reply where pNum=?";
		Connection conn = null;
		PreparedStatement pstmt = null;
		try {
			conn = DBManager.getConnection();
			conn.setAutoCommit(false);
			//댓글삭제
			pstmt = conn.prepareStatement(sql2);
			pstmt.setString(1, num);
			pstmt.executeUpdate();
			//부모글삭제
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, num);
			pstmt.executeUpdate();
			
			conn.commit();
		} catch (SQLException e) {
			e.printStackTrace();
			if(conn!=null) {
				try {
					conn.rollback();
				} catch (SQLException e1) {					
					e1.printStackTrace();
				}
			}
		}
	}

'TIS_2021 > 인공지능2021_1기' 카테고리의 다른 글

5/31 board  (0) 2021.05.31
5/26 댓글게시판  (0) 2021.05.26
5/26 deleteBoard 부모글삭제시 댓글삭제. 트랜잭션처리  (0) 2021.05.26
5/24 product  (0) 2021.05.24
ReactJS Ajax  (0) 2021.05.14
4/29 삼성데모 수정  (0) 2021.04.29
0 Comments
댓글쓰기 폼