데일리로그C:
Published 2023. 4. 17. 18:25
기한 지나면 삭제 처리 Memo

[admin/cart/list.jsp]

<input type="button" class="j_but" id="deadline_del" value="기간만료(일주일)삭제" onclick="deadline_del('${ct_date}')">

<script>
	/* 기간만료 삭제 */
	function deadline_del(ct_date) {
		location.href="deadline_del";
	}
</script>

 

[DeadlineDel.java]

Date today = new Date(); //현재 날짜

Date day_77 = new Date(today.getTime() - (long)(1000*60*60*24*7)); //현재 날짜 - 7일

SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //년-월-일 변경

String day_7 = sd.format(day_77); //7일전 날짜를 문자열 변수에 대입

//System.out.println("==7일전:"+day_7);

AdminCartDAO dao = new AdminCartDAO();

dao.dead_del(day_7);

response.sendRedirect("list");

 

[AdminCartDAO]

//기간만료 삭제
public void dead_del(String str) {
    d.getCon();

    try {

        String sql ="delete from cart where ct_date <= '"+str+"' and ct_status='준비' ";

        pstmt = d.con.prepareStatement(sql);

        pstmt.executeUpdate();

        pstmt.close();
        d.con.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

'Memo' 카테고리의 다른 글

placeholder 줄바꿈  (0) 2023.04.19
confirm  (0) 2023.04.18
EL 기호(약어) 정리  (0) 2023.04.17
Q&A 댓글  (0) 2023.04.17
팝업창  (0) 2023.04.10
profile

데일리로그C:

@망밍

포스팅이 도움됐다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

profile on loading

Loading...