본문 바로가기

개발자노트/DBMS

[SQL] JDBC에서 delete

final String sql_delete="DELETE FROM STUDENT WHERE SID=?";

public boolean deleteStudent(StudentVO vo) {
		conn=JDBCUtil.connect();
		try {
			pstmt=conn.prepareStatement(sql_delete);
			pstmt.setInt(1, vo.getSid());
			int res=pstmt.executeUpdate(); // 반환값이 int, 수행한 횟수를 나타냄 1명삭제 2명삭제..등등
			if(res==0) {
				return false;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		} finally {
			JDBCUtil.disconnect(pstmt, conn);
		}
		return true;
	}