[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 |