본문 바로가기

MVC1/캘린더

캘린더

bbslist.jsp에서 <a href="./calendar/calcalendar.jsp">일정관리</a>로 이동시킴

 

 

calclaendar.jsp

<%!
// nvl 함수
public boolean nvl(String msg){
	return msg == null||msg.trim().equals("")?true:false;
}
%>    

<%
Object ologin = session.getAttribute("login");
MemberDto mem = null;
if(ologin == null){
	response.sendRedirect("goCheck.jsp?proc=login");	
}

mem = (MemberDto)ologin;
%>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<h4 align="left" style="background-color: #f0f0f0">환영합니다 <%=mem.getId() %>님</h4>

<%
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.DATE, 1);	// 7/31 -> 7/01

	String syear = request.getParameter("year");
	String smonth = request.getParameter("month");
	
	int year = cal.get(Calendar.YEAR);
	if(nvl(syear) == false){	// parameter가 넘어 왔을 때
		year = Integer.parseInt(syear);
	}
	
	int month = cal.get(Calendar.MONTH) + 1;
	if(nvl(smonth) == false){
		month = Integer.parseInt(smonth);
	}
	
	if(month < 1){
		month = 12;
		year--; 
	}
	if(month > 12){
		month = 1;
		year++;
	}
	
	cal.set(year, month - 1, 1);	// 연 월 일 셋팅이 완료 -> 2020 07 31

	// 요일
	int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
	
	// << year--
	String pp = String.format("<a href='%s?year=%d&month=%d'>" + "<img src='../image/left.gif'></a>", 
									"calendar.jsp", year-1, month);
	
	// < month--
	String p = String.format("<a href='%s?year=%d&month=%d'>" + "<img src='../image/prec.gif'></a>", 
									"calendar.jsp", year, month-1);
	
	// > month++
	String n = String.format("<a href='%s?year=%d&month=%d'>" + "<img src='../image/next.gif'></a>", 
									"calendar.jsp", year, month+1);
	
	// >> year++
	String nn = String.format("<a href='%s?year=%d&month=%d'>" + "<img src='../image/last.gif'></a>", 
									"calendar.jsp", year+1, month);
	
	CalendarDao dao = CalendarDao.getInstance();
	List<CalendarDto> list = dao.getCalendarList(mem.getId(), year + UtilEx.two(month + ""));
		
%>

<div align="center">

<table border="1">
<col width="100"><col width="100"><col width="100"><col width="100">
<col width="100"><col width="100"><col width="100">

<tr height="100">
	<td colspan="7" align="center" style="padding-top: 20px">
		<%=pp %>&nbsp;&nbsp;<%=p %>&nbsp;
		
		<font color="black" style="font-size: 50px">
			<%=String.format("%d년&nbsp;&nbsp;%2d월", year, month) %>
		</font>
		
		<%=n %>&nbsp;&nbsp;<%=nn %>	
	</td>	
</tr>

<tr height="50">
	<th align="center">일</th>
	<th align="center">월</th>
	<th align="center">화</th>
	<th align="center">수</th>
	<th align="center">목</th>
	<th align="center">금</th>
	<th align="center">토</th>
</tr> 

<tr height="100" align="left" valign="top">
<%
// 위쪽 빈칸
for(int i = 1;i < dayOfWeek; i++){
	%>
	<td style="background-color: #cecece">&nbsp;</td>	
	<%
}
%>

<%-- 날짜 --%>
<%
int lastday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for(int i = 1; i <= lastday; i++){
	%>
	<td>
		<%=UtilEx.callist(year, month, i) %>&nbsp;&nbsp;<%=UtilEx.showPen(year, month, i) %>
		<%=UtilEx.makeTable(year, month, i, list) %>	
	</td>	
	<%
	if( (i + dayOfWeek - 1) % 7 == 0 && i != lastday){
		%>
		</tr><tr height="100" align="left" valign="top">		
		<%
	}	
}
%>

<%--밑칸 --%>
<%
cal.set(Calendar.DATE, lastday); // 그달의 마지막 날짜로 셋팅
int weekday = cal.get(Calendar.DAY_OF_WEEK);
for(int i = 0;i < 7 - weekday; i++){
	%>	
	<td style="background-color: #cecece">&nbsp;</td>	
	<%
}

%>
</tr>
</table>
</div>
</body>
</html>

 

 

 

 

caldetail.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>caldetail.jsp</title>
</head>
<body>

<%!

public String toDates(String mdate){
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy년 MM월 dd일 hh시 mm분");
	
	String s = mdate.substring(0, 4) + "-" 	// yyyy
			+ mdate.substring(4, 6) + "-"	// MM
			+ mdate.substring(6, 8) + " " 	// dd
			+ mdate.substring(8, 10) + ":"	// hh
			+ mdate.substring(10, 12) + ":00"; 
	Timestamp d = Timestamp.valueOf(s);
	
	return sdf.format(d);	
}

public String toOne(String msg){	// 08 -> 8
	return msg.charAt(0)=='0'?msg.charAt(1) + "": msg.trim();
}
%>

<%
String sseq = request.getParameter("seq");
int seq = Integer.parseInt(sseq);

CalendarDao dao = CalendarDao.getInstance();
CalendarDto dto = dao.getDay(seq);

%>

<h1>일정 보기</h1>
<hr>

<div align="center">

<table border="1">
<col width="200"><col width="500">

<tr>
	<td>아이디</td>
	<td><%=dto.getId() %></td>
</tr>

<tr>
	<td>제목</td>
	<td><%=dto.getTitle() %></td>
</tr>

<tr>
	<td>일정</td>
	<td><%=toDates(dto.getRdate()) %></td>
</tr>

<tr>
	<td>내용</td>
	<td>
		<textarea rows="20" cols="60" readonly="readonly"><%=dto.getContent() %>
		</textarea>
	</td>
</tr>

<tr>
	<td colspan="2" align="center">
		<input type="button" value="수정" onclick="location.href='calupdate.jsp?seq=<%=dto.getSeq() %>'">
		<input type="button" value="삭제" onclick="location.href='caldel.jsp?seq=<%=dto.getSeq() %>'">
	</td>
</tr>
</table>
</div>
</body>
</html>

 

 

 

 

callist.jsp

<%!
// Date -> String	18/10/02	
// String -> Date   yyyy-mm-dd
public String toDates(String mdate){
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy년 MM월 dd일 hh시 mm분");
	
	// 201810021607	-> 2018-10-02 16:07 
	String s = mdate.substring(0, 4) + "-"	// yyyy 
			+ mdate.substring(4, 6) + "-"	// MM
			+ mdate.substring(6, 8) + " "	// dd
			+ mdate.substring(8, 10) + ":"	// hh
			+ mdate.substring(10, 12) + ":00";
	
	Timestamp d = Timestamp.valueOf(s);
	
	return sdf.format(d);
}
%>        

<%
MemberDto user = (MemberDto)session.getAttribute("login");

String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");

String dates = year + UtilEx.two(month + "") + UtilEx.two(day + "");

CalendarDao dao = CalendarDao.getInstance(); 
List<CalendarDto> list = dao.getDayList(user.getId(), dates);
/* 
for(int i = 0;i < list.size(); i++){
	CalendarDto c = list.get(i);
	System.out.println(c.toString());	
}
 */
%>

    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>callist.jsp</title>
</head>
<body>

<h2><%=year %>년 <%=month %>월 <%=day %>일 일정</h2>

<hr>

<div align="center">

<table border="1">
<col width="100"><col width="300"><col width="450"><col width="50">

<tr bgcolor="#09bbaa">
<td>번호</td><td>시간</td><td>제목</td><td>삭제</td>
</tr>

<%
for(int i = 0;i < list.size(); i++ ){
	CalendarDto dto = list.get(i);
	%>
	<tr>	
		<td><%=i + 1 %></td>
		<td><%=toDates(dto.getRdate()) %></td>
		<td>
			<a href="caldetail.jsp?seq=<%=dto.getSeq() %>">
				<%=dto.getTitle() %>
			</a>
		</td>
		<td>
			<form action="caldel.jsp" method="post">
				<input type="hidden" name="seq" value="<%=dto.getSeq() %>">
				<input type="submit" value="일정삭제">
			</form>
		</td>	
	</tr>
	<%
}
%>
</table>
</div>
<a href="<%=String.format("%s?year=%s&month=%s", "calendar.jsp", year, month) %>">일정보기</a>
</body>
</html>

 

 

 

 

caldwrite.jsp

<%
String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");

MemberDto mem = (MemberDto)session.getAttribute("login");

System.out.println("year:" + year);
System.out.println("month:" + month);
System.out.println("day:" + day);
%>    
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>calwrite</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

<%
// 범위를 설정하는 기준
Calendar cal = Calendar.getInstance();
int tyear = cal.get(Calendar.YEAR);
int tmonth = cal.get(Calendar.MONTH) + 1;	// 0 ~ 11
int tday = cal.get(Calendar.DATE);
int thour = cal.get(Calendar.HOUR_OF_DAY);
int tmin = cal.get(Calendar.MINUTE);
%>

<h1>일정 추가</h1>

<div align="center">

<form action="calwriteAf.jsp" method="post">

<table border="1">
<col width="200"><col width="500">
<tr>
	<th>ID</th>
	<td>
		<%=mem.getId() %>
		<input type="hidden" name="id" value="<%=mem.getId() %>"> 
	</td>
</tr>
<tr>
	<th>제목</th>
	<td>
		<input type="text" size="60" name="title">
	</td>
</tr>
<tr>
	<th>일정</th>
	<td>
		<select name="year">
		<%
			for(int i = tyear - 5;i < tyear + 5; i++){
				%>
				<option <%=year.equals(i + "")?"selected='selected'":"" %> value="<%=i %>">
					<%=i %>
				</option>				
				<%
			}		
		%>		
		</select>년
		
		<select name="month">
		<%
			for(int i = 1;i <= 12; i++){
				%>
				<option <%=month.equals(i + "")?"selected='selected'":"" %> value="<%=i %>">
					<%=i %>
				</option>				
				<%
			}		
		%>		
		</select>월
		
		<select name="day">
		<%
			for(int i = 1;i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
				%>
				<option <%=day.equals(i + "")?"selected='selected'":"" %> value="<%=i %>">
					<%=i %>
				</option>				
				<%
			}		
		%>		
		</select>일
		
		<select name="hour">
		<%
			for(int i = 0;i < 24; i++){
				%>
				<option <%=(thour + "").equals(i + "")?"selected='selected'":"" %> value="<%=i %>">
					<%=i %>
				</option>				
				<%
			}		
		%>		
		</select>시
		
		<select name="min">
		<%
			for(int i = 0;i < 60; i++){
				%>
				<option <%=(tmin + "").equals(i + "")?"selected='selected'":"" %> value="<%=i %>">
					<%=i %>
				</option>				
				<%
			}		
		%>		
		</select>분		
	</td>
</tr>

<tr>
	<th>내용</th>
	<td>
		<textarea rows="20" cols="60" name="content"></textarea>
	</td>
</tr>

<tr>
	<td colspan="2">
		<input type="submit" value="일정추가">
	</td>
</tr>

</table>

</form>

</div>

<script type="text/javascript">

$("select[name='day']").val("<%=day %>");

$(document).ready(function() {
	$("select[name='month']").change( setday );	
});

function setday() {
	// 해당 년도의 월을 통해서 마지막날을 구한다. 
	let year = $("select[name='year']").val();
	let month = $("select[name='month']").val();
	
	let lastday = (new Date(year, month, 0)).getDate();
//	alert(lastday);

	// 날짜 적용
	let str = "";
	for(i = 1;i <= lastday; i++){
		str += "<option value='" + i + "'>" + i + "</option>";
	}
	
	$("select[name='day']").html( str );
}
</script>
</body>
</html>

 

 

 

 

calwriteAf.jsp

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
request.setCharacterEncoding("utf-8");

String id = request.getParameter("id");
String title = request.getParameter("title");
String content = request.getParameter("content");

String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");
String hour = request.getParameter("hour");
String min = request.getParameter("min");

System.out.println(id + " " + title + " " + content);
System.out.println(year + " " + month + " " + day + " " + hour + " " + min);

// 2020/07/31 14:52 -> 202007311452

String rdate = year + UtilEx.two(month) + UtilEx.two(day) + UtilEx.two(hour) + UtilEx.two(min);
System.out.println(rdate);

CalendarDao dao = CalendarDao.getInstance();

boolean isS = dao.addCalendar(new CalendarDto(id, title, content, rdate));
if(isS){
	%>
	<script type="text/javascript">
	alert("일정이 추가되었습니다");
	location.href = "calendar.jsp";
	</script>
	<%
}else{
	%>
	<script type="text/javascript">
	alert("일정이 추가되지 않았습니다");
	location.href = "calendar.jsp";
	</script>
	<%
}
%>

<%--
	caldetail.jsp -> 그날의 제목 내용을 볼 수 있음
	callist.jsp -> 일별일정을 모두 볼수 있음
	calupdate.jsp -> 수정
	caldelete.jsp -> 삭제 
 --%>
</body>
</html>

 

 

 

 

 

calupdate.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>calupdate</title>
</head>
<body>

<%!
public String toDates(String mdate){
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy년 MM월 dd일 hh시 mm분");
	
	String s = mdate.substring(0, 4) + "-" 	// yyyy
			+ mdate.substring(4, 6) + "-"	// MM
			+ mdate.substring(6, 8) + " " 	// dd
			+ mdate.substring(8, 10) + ":"	// hh
			+ mdate.substring(10, 12) + ":00"; 
	Timestamp d = Timestamp.valueOf(s);
	
	return sdf.format(d);	
}

public String toOne(String msg){	// 08 -> 8
	return msg.charAt(0)=='0'?msg.charAt(1) + "": msg.trim();
}

%>

<%
Calendar cal = Calendar.getInstance();
int tyear = cal.get(Calendar.YEAR);

String sseq = request.getParameter("seq");
int seq = Integer.parseInt(sseq);

CalendarDao dao = CalendarDao.getInstance();
CalendarDto dto = dao.getDay(seq);

String year = dto.getRdate().substring(0, 4);
String month = toOne(dto.getRdate().substring(4, 6));
String day = toOne(dto.getRdate().substring(6, 8));
String hour = toOne(dto.getRdate().substring(8, 10));
String min = toOne(dto.getRdate().substring(10, 12));

%>


<h1>일정 수정</h1>
<hr>

<div align="center">


<form action="calupdateAf.jsp" method="post">

<table border="1">
<col width="200"><col width="500">

<tr>
	<td>아이디<input type="hidden" name="seq" value="<%=dto.getSeq() %>">
	</td>
	<td>
		<input type="text" name="id" value="<%=dto.getId() %>" readonly="readonly">
	</td>
</tr> 

<tr>
	<td>제목</td>
	<td>
		<input type="text" size="60" name="title" value="<%=dto.getTitle() %>">
	</td>
</tr>

<tr>
	<td>일정</td>
	<td>
	
	<select name="year">
	<%
	for(int i = tyear - 5;i < tyear + 6; i++){
		%>
		<option <%=year.equals(i + "")?"selected='selected'":"" %> 
			value="<%=i %>"><%=i %></option>		
		<%	
	}	
	%>	
	</select>년	
	
	<select name="month">
	<%
	for(int i = 1;i <= 12; i++){
		%>
		<option <%=month.equals(i + "")?"selected='selected'":"" %> 
			value="<%=i %>"><%=i %></option>		
		<%	
	}	
	%>	
	</select>월
	
	<select name="day">
	<%
	for(int i = 1;i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
		%>
		<option <%=day.equals(i + "")?"selected='selected'":"" %> 
			value="<%=i %>"><%=i %></option>		
		<%	
	}	
	%>	
	</select>일
	
	<select name="hour">
	<%
	for(int i = 0;i < 24; i++){
		%>
		<option <%=(hour + "").equals(i + "")?"selected='selected'":"" %> 
			value="<%=i %>"><%=i %></option>		
		<%	
	}	
	%>	
	</select>시
	
	<select name="min">
	<%
	for(int i = 0;i < 60; i++){
		%>
		<option <%=(min + "").equals(i + "")?"selected='selected'":"" %> 
			value="<%=i %>"><%=i %></option>		
		<%	
	}	
	%>	
	</select>분
	
	</td>
</tr>

<tr>
	<td>내용</td>
	<td>
		<textarea rows="20" cols="60" name="content"><%=dto.getContent() %> </textarea>
	</td>
</tr>

<tr>
	<td colspan="2">
		<input type="button" value="수정" onclick="modify()">
	</td>
</tr>


</table>

</form>

</div>

<script type="text/javascript">
function modify() {
	var f = document.forms[0];
	f.submit();
}
</script>

<%
String url = String.format("%s?year=%s&month=%s", 
						"calendar.jsp", year, month);
%>
<a href="<%=url %>">일정보기</a>
</body>
</html>

 

 

calupdateAf.jsp

<%@page import="calendarEx.CalendarDto"%>
<%@page import="calendarEx.CalendarDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
request.setCharacterEncoding("utf-8");
%>    
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>calupdateAf.jsp</title>
</head>
<body>

<%!
public String two(String msg){
	return msg.trim().length()<2?"0"+msg:msg.trim();	// 1 ~ 9 -> 01
}
%>

<%
int seq = Integer.parseInt(request.getParameter("seq"));

String title = request.getParameter("title");
String content = request.getParameter("content");

String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");
String hour = request.getParameter("hour");
String min = request.getParameter("min");

String rdate = year + two(month) + two(day) + two(hour) + two(min);

CalendarDao dao = CalendarDao.getInstance();

boolean isS = dao.updateCalendar(new CalendarDto(seq, "", title, content, rdate, ""));

// String urlDetail = String.format("%s?seq=%d", "caldetail.jsp", seq);
String urllist = String.format("%s?year=%s&month=%s", "calendar.jsp", year, month);

if(isS){	
	%>
	<script type="text/javascript">
	alert("성공적으로 일정을 수정했습니다");
	location.href="<%=urllist %>";	
	</script>
	<%
}else{	
	%>
	<script type="text/javascript">
	alert("일정을 수정하지 못했습니다");
	location.href="<%=urllist %>";	
	</script>
	<%
}
%>
</body>
</html>

 

 

 

 

calde.jsp

<%@page import="calendarEx.CalendarDto"%>
<%@page import="calendarEx.CalendarDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>caldel.jsp</title>
</head>
<body>

<%!
public String toOne(String msg){	// 08 -> 8
	return msg.charAt(0)=='0'?msg.charAt(1) + "": msg.trim();
}

public String two(String msg){		// 8 -> 08
	return msg.trim().length()<2?"0"+msg:msg.trim();	// 1 ~ 9 -> 01
}
%>

<%
int seq = Integer.parseInt(request.getParameter("seq"));

CalendarDao dao = CalendarDao.getInstance();
CalendarDto dto = dao.getDay(seq);
boolean isS = dao.deleteCalendar(seq);

String year = dto.getRdate().substring(0, 4);	// 년도
String month = toOne(dto.getRdate().substring(4, 6));	// 월
String day = toOne(dto.getRdate().substring(6, 8));		// 일

String url = String.format("%s?year=%s&month=%s&day=%s", 
							"calendar.jsp", year, month, day);

if(isS){
	%>
	<script type="text/javascript">
	alert("성공적으로 삭제 되었습니다");
	location.href="<%=url %>";
	</script>	
	<%
}else{	
	%>
	<script type="text/javascript">
	alert("삭제하지 못했습니다");
	location.href="<%=url %>";
	</script>
	<%
}	
%>
</body>
</html>

 

 

 

 

CalendarDao.java

package calendarEx;

public class CalendarDao {
	
	private static CalendarDao dao = new CalendarDao();

	private CalendarDao() {
	}
	
	public static CalendarDao getInstance() {
		return dao;		
	}
	
	public List<CalendarDto> getCalendarList(String id, String yyyyMM) {
		
		String sql = " SELECT SEQ, ID, TITLE, CONTENT, RDATE, WDATE " + 
					" FROM (" + 
					"		SELECT ROW_NUMBER()OVER(PARTITION BY SUBSTR(RDATE, 1, 8)ORDER BY RDATE ASC) AS RNUM, " + 
					"			SEQ, ID, TITLE, CONTENT, RDATE, WDATE " + 
					"		FROM CALENDAR " + 
					"		WHERE ID=? AND SUBSTR(RDATE, 1, 6)=? " + 
					")" + 
				" WHERE RNUM BETWEEN 1 AND 5 ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		ResultSet rs = null;
		
		List<CalendarDto> list = new ArrayList<CalendarDto>();
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("1/6 getCalendarList success");
			
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, id);
			psmt.setString(2, yyyyMM);
			System.out.println("2/6 getCalendarList success");
			
			rs = psmt.executeQuery();
			System.out.println("3/6 getCalendarList success");
			
			while(rs.next()) {
				int i = 1;
				CalendarDto dto = new CalendarDto(	rs.getInt(i++), 
													rs.getString(i++), 
													rs.getString(i++), 
													rs.getString(i++), 
													rs.getString(i++), 
													rs.getString(i++) );				
				list.add(dto);
			}
			System.out.println("4/6 getCalendarList success");
			
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			DBClose.close(psmt, conn, rs);			
		}
		
		return list;
	}
	
	public boolean addCalendar(CalendarDto cal) {
		
		String sql = " INSERT INTO CALENDAR(SEQ, ID, TITLE, CONTENT, RDATE, WDATE) "
					+ " VALUES(SEQ_CAL.NEXTVAL, ?, ?, ?, ?, SYSDATE) ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		
		int count = 0;
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("1/6 addCalendar success");
			
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, cal.getId());
			psmt.setString(2, cal.getTitle());
			psmt.setString(3, cal.getContent());
			psmt.setString(4, cal.getRdate());
			System.out.println("2/6 addCalendar success");
			
			count = psmt.executeUpdate();
			System.out.println("3/6 addCalendar success");
			
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			DBClose.close(psmt, conn, null);			
		}
		
		return count>0?true:false;		
	}
	
	public CalendarDto getDay(int seq) {
		String sql = " SELECT "
				+ " SEQ, ID, TITLE, CONTENT, RDATE, WDATE "
				+ " FROM CALENDAR "
				+ " WHERE SEQ=? ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		ResultSet rs = null;
		
		CalendarDto dto = null;
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("2/6 S getDay");	
			
			psmt = conn.prepareStatement(sql);
			psmt.setInt(1, seq);
			System.out.println("3/6 S getDay");	
			
			rs = psmt.executeQuery();
			System.out.println("4/6 S getDay");	
			
			while(rs.next()){
				dto = new CalendarDto();
				dto.setSeq(rs.getInt(1));
				dto.setId(rs.getString(2));
				dto.setTitle(rs.getString(3));
				dto.setContent(rs.getString(4));
				dto.setRdate(rs.getString(5));
				dto.setWdate(rs.getString(6));						
			}	
			System.out.println("5/6 S getDay");			
						
		} catch (Exception e) {			
			e.printStackTrace();
		} finally{
			DBClose.close(psmt, conn, rs);
			System.out.println("6/6 S getDay");			
		}		
		
		return dto;
	}
	
	public List<CalendarDto> getDayList(String id, String yyyymmdd) {
		
		String sql =  " SELECT SEQ, ID, TITLE, CONTENT, "
					+ "		RDATE, WDATE "
					+ " FROM CALENDAR "
					+ " WHERE ID=? AND SUBSTR(RDATE, 1, 8)=? "
					+ " ORDER BY RDATE ASC ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		ResultSet rs = null;
		
		List<CalendarDto> list = new ArrayList<CalendarDto>();
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("1/6 S getDayList");
			
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, id.trim());
			psmt.setString(2, yyyymmdd.trim());
			System.out.println("2/6 S getDayList");
			
			rs = psmt.executeQuery();
			System.out.println("3/6 S getDayList");
			
			while(rs.next()) {
				int i = 1;
				CalendarDto dto = new CalendarDto();
				dto.setSeq(rs.getInt(i++));
				dto.setId(rs.getString(i++));
				dto.setTitle(rs.getString(i++));
				dto.setContent(rs.getString(i++));
				dto.setRdate(rs.getString(i++));
				dto.setWdate(rs.getString(i++));
							
				list.add(dto);
			}	
			System.out.println("4/6 S getDayList");
			
		} catch (Exception e) {
			System.out.println("F getDayList");
			e.printStackTrace();
		} finally {
			DBClose.close(psmt, conn, rs);			
		}
		
		return list;
	}
	
	public boolean deleteCalendar(int seq) {
		
		String sql = " DELETE FROM CALENDAR"
				+ " WHERE SEQ=? ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		
		int count = 0;
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("2/6 S deleteCalendar");	
			
			psmt = conn.prepareStatement(sql);
			psmt.setInt(1, seq);
			System.out.println("3/6 S deleteCalendar");	
			
			count = psmt.executeUpdate();
			System.out.println("4/6 S deleteCalendar");				
			
		} catch (Exception e) {			
			e.printStackTrace();
		} finally{
			DBClose.close(psmt, conn, null);			
			System.out.println("5/6 S deleteCalendar");	
		}
		
		return count>0?true:false;
	}
	
	public boolean updateCalendar(CalendarDto dto) {
		
		String sql = " UPDATE CALENDAR SET "
				+ " TITLE=?, CONTENT=?, RDATE=?, WDATE=SYSDATE "
				+ " WHERE SEQ=? ";
		
		Connection conn = null;
		PreparedStatement psmt = null;
		
		int count = 0;
		
		try {
			conn = DBConnection.getConnection();
			System.out.println("2/6 S updateCalendar");	
			
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, dto.getTitle());
			psmt.setString(2, dto.getContent());
			psmt.setString(3, dto.getRdate());
			psmt.setInt(4, dto.getSeq());
			System.out.println("3/6 S updateCalendar");	
			
			count = psmt.executeUpdate();
			System.out.println("4/6 S updateCalendar");	
			
		} catch (Exception e) {			
			e.printStackTrace();
		} finally{
			DBClose.close(psmt, conn, null);	
			System.out.println("5/6 S updateCalendar");
		}
		return count>0?true:false;
	}
}

 

 

 

 

 

 

 

CalendarDto.java

package calendarEx;

import java.io.Serializable;
/*
DROP TABLE CALENDAR
CASCADE CONSTRAINTS;

DROP SEQUENCE SEQ_CAL;

CREATE TABLE CALENDAR(
	SEQ NUMBER(8) PRIMARY KEY,
	ID VARCHAR2(50) NOT NULL,
	TITLE VARCHAR2(200) NOT NULL,
	CONTENT VARCHAR2(4000) NOT NULL,
	RDATE VARCHAR2(12) NOT NULL,	
	WDATE DATE NOT NULL	
);

CREATE SEQUENCE SEQ_CAL
START WITH 1
INCREMENT BY 1;

ALTER TABLE CALENDAR
ADD CONSTRAINT FK_CAL_ID FOREIGN KEY(ID)
REFERENCES MEMBER(ID);
*/
public class CalendarDto implements Serializable {
	
	private int seq;
	private String id;
	private String title;
	private String content;
	private String rdate;	// 일정이 있는 날  20/08/03
	private String wdate;	// 작성일		  20/07/31()	
	
	public CalendarDto() {
	}
	public CalendarDto(int seq, String id, String title, String content, String rdate, String wdate) {
		super();
		this.seq = seq;
		this.id = id;
		this.title = title;
		this.content = content;
		this.rdate = rdate;
		this.wdate = wdate;
	}
	public CalendarDto(String id, String title, String content, String rdate) {
		super();
		this.id = id;
		this.title = title;
		this.content = content;
		this.rdate = rdate;
	}
	public int getSeq() {
		return seq;
	}
	public void setSeq(int seq) {
		this.seq = seq;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getRdate() {
		return rdate;
	}
	public void setRdate(String rdate) {
		this.rdate = rdate;
	}
	public String getWdate() {
		return wdate;
	}
	public void setWdate(String wdate) {
		this.wdate = wdate;
	}
	@Override
	public String toString() {
		return "CalendarDto [seq=" + seq + ", id=" + id + ", title=" + title + ", content=" + content + ", rdate="
				+ rdate + ", wdate=" + wdate + "]";
	}
}