( ๋ฐ์ดํฐ๋ฒ ์ด์ค ๐๐ป ์๋ฒ ๐๐ป ํ๋ก ํธ ๐๐ป ๋ฐฑ์๋ ) [ OPEN ]
create table member_tbl_02 (
custno number(6) not null primary key,
custname varchar2(20),
phone varchar2(13),
address varchar2(60),
joindate date,
grade char(1),
city char(2)
);
create table money_tbl_02 (
custno number(6),
salenol number(8),
pcost number(8),
amount number(4),
price number(8),
pcode varchar2(4),
sdate date,
CONSTRAINT money_pk PRIMARY KEY (custno,salenol)
);
INSERT INTO member_tbl_02 VALUES (100001,'๊นํ๋ณต','010-1111-2222','์์ธ ๋๋๋ฌธ๊ตฌ ํ๊ฒฝ1๋','20151202','A','01');
INSERT INTO member_tbl_02 VALUES (100002,'์ด์ถ๋ณต','010-1111-3333','์์ธ ๋๋๋ฌธ๊ตฌ ํ๊ฒฝ2๋','20151206','B','01');
INSERT INTO member_tbl_02 VALUES (100003,'์ฅ๋ฏฟ์','010-1111-4444','์ธ๋ฆ๊ตฐ ์ธ๋ฆ์ ๋
๋1๋ฆฌ','20151001','B','30');
INSERT INTO member_tbl_02 VALUES (100004,'์ต์ฌ๋','010-1111-5555','์ธ๋ฆ๊ตฐ ์ธ๋ฆ์ ๋
๋2๋ฆฌ','20151113','A','30');
INSERT INTO member_tbl_02 VALUES (100005,'์งํํ','010-1111-6666','์ ์ฃผ๋ ์ ์ฃผ์ ์ธ๋๋ฌด๊ณจ','20151225','B','60');
INSERT INTO member_tbl_02 VALUES (100006,'์ฐจ๊ณต๋จ','010-1111-7777','์ ์ฃผ๋ ์ ์ฃผ์ ๊ฐ๋๋ฌด๊ณจ','20151211','C','60');
INSERT INTO money_tbl_02 VALUES (100001,20160001,500,5,2500,'A001','20160101');
INSERT INTO money_tbl_02 VALUES (100001,20160002,1000,4,4000,'A002','20160101');
INSERT INTO money_tbl_02 VALUES (100001,20160003,500,3,1500,'A008','20160101');
INSERT INTO money_tbl_02 VALUES (100002,20160004,2000,1,2000,'A004','20160102');
INSERT INTO money_tbl_02 VALUES (100002,20160005,500,1,500,'A001','20160103');
INSERT INTO money_tbl_02 VALUES (100003,20160006,1500,2,3000,'A003','20160103');
INSERT INTO money_tbl_02 VALUES (100004,20160007,500,2,1000,'A001','20160104');
INSERT INTO money_tbl_02 VALUES (100004,20160008,300,1,300,'A005','20160104');
INSERT INTO money_tbl_02 VALUES (100004,20160009,600,1,600,'A006','20160104');
INSERT INTO money_tbl_02 VALUES (100004,20160010,3000,1,3000,'A007','20160106');
( ๋ฐ์ดํฐ๋ฒ ์ด์ค ๐๐ป ์๋ฒ ๐๐ป ํ๋ก ํธ ๐๐ป ๋ฐฑ์๋ ) [ OPEN ]
controller/Controller.java (*Servlet file ์์ฑ)
package controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DAO.MemberDAO;
@WebServlet("/")
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPro(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPro(request, response);
}
protected void doPro(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri = request.getRequestURI();
String context = request.getContextPath();
String command = uri.substring(context.length());
String site = null;
System.out.println("command:"+command);
MemberDAO member = new MemberDAO();
switch(command) {
case "/home" :
site = "index.jsp";
break;
case "/add" :
site = member.nextCustno(request, response);
break;
case "/list" :
site = member.selectAll(request, response);
break;
case "/result" :
site = member.selectResult(request, response);
break;
case "/insert" :
site = member.insert(request, response);
break;
case "/modify" :
site = member.modify(request, response);
break;
case "/update" :
int result1 = member.update(request, response);
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
if(result1 == 1) {
out.println("<script>");
out.println(" alert('ํ์์์ ์ด ์๋ฃ ๋์์ต๋๋ค!'); location.href='"+context+"'; ");
out.println("</script>");
out.flush();
}else {
out.println("<script>");
out.println("alert('์์ ์คํจ!'); location.href='"+context+"'; ");
out.println("</script>");
out.flush();
}
break;
case "/delete" :
int result2 = member.delete(request, response);
response.setContentType("text/html; charset=UTF-8");
out = response.getWriter();
if(result2 == 1) {
out.println("<script>");
out.println(" alert('ํ์์ญ์ ๊ฐ ์๋ฃ ๋์์ต๋๋ค!'); location.href='"+context+"'; ");
out.println("</script>");
out.flush();
}else {
out.println("<script>");
out.println("alert('์ญ์ ์คํจ!'); location.href='"+context+"'; ");
out.println("</script>");
out.flush();
}
break;
}
RequestDispatcher dispatcher = request.getRequestDispatcher(site);
dispatcher.forward(request, response);
}
}
DTO/Member.java
package DTO;
public class Member {
int custno;
String custname;
String phone;
String address;
String joindate;
String grade;
String city;
public int getCustno() {
return custno;
}
public void setCustno(int custno) {
this.custno = custno;
}
public String getCustname() {
return custname;
}
public void setCustname(String custname) {
this.custname = custname;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getJoindate() {
return joindate;
}
public void setJoindate(String joindate) {
this.joindate = joindate;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
DTO/Money.java
package DTO;
public class Money {
int custno;
String custname;
String grade;
int price;
public int getCustno() {
return custno;
}
public void setCustno(int custno) {
this.custno = custno;
}
public String getCustname() {
return custname;
}
public void setCustname(String custname) {
this.custname = custname;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
</web-app>
tomcat9/lib/servlet-api.jar
( ๋ฐ์ดํฐ๋ฒ ์ด์ค ๐๐ป ์๋ฒ ๐๐ป ํ๋ก ํธ ๐๐ป ๋ฐฑ์๋ ) [ OPEN ]
index.jsp (๋ฉ์ธ)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
<link rel="stylesheet" href="style.css?ver=1">
</head>
<body>
<%@ include file="topmenu.jsp" %>
<section>
<div class="title">
์ผํ๋ชฐ ํ์๊ด๋ฆฌ ํ๋ก๊ทธ๋จ
</div>
<div class="main">
์ผํ๋ชฐ ํ์์ ๋ณด์ ํ์๋งค์ถ์ ๋ณด ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๊ตฌ์ถํ๊ณ ํ์๊ด๋ฆฌ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ ํ๋ก๊ทธ๋จ์ด๋ค.<br>
ํ๋ก๊ทธ๋จ ์์ฑ ์์
<ul>
<li>ํ์์ ๋ณด ํ
์ด๋ธ์ ์์ฑํ๋ค.</li>
<li>ํ์์ ๋ณด, ๋งค์ถ์ ๋ณด ํ
์ด๋ธ์ ์ ์๋ ๋ฌธ์ ์ง์ ์ฐธ์กฐ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ ์์ฑํ๋ค.</li>
<li>ํ์์ ๋ณด ์
๋ ฅ ํ๋ฉดํ๋ก๊ทธ๋จ์ ์์ฑํ๋ค.</li>
<li>ํ์์ ๋ณด ์กฐํ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ค.</li>
<li>ํ์๋งค์ถ์ ๋ณด ์กฐํ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ค.</li>
</ul>
</div>
</section>
<%@ include file="footer.jsp" %>
</body>
</html>
add.jsp (ํ์๋ฑ๋ก)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="DTO.Member" %>
<%
request.setCharacterEncoding("UTF-8");
int custno = 0;
custno = (Integer)request.getAttribute("custno");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css?ver=1">
</head>
<body>
<%@ include file="topmenu.jsp" %>
<section>
<div class="title">
ํ์ผํ ํ์ ๋ฑ๋ก
</div>
<form name="frm" action="insert">
<input type="hidden" id="GUBUN" value="insert" >
<div class="wrapper">
<table>
<tr>
<th>ํ์๋ฒํธ(์๋๋ฐ์)</th>
<td><input name="custno" value="<%=custno %>" readonly value="1"></td>
</tr>
<tr>
<th>ํ์์ฑ๋ช
</th>
<td><input type="text" name="custname" ></td>
</tr>
<tr>
<th>ํ์์ ํ</th>
<td><input type="text" name="phone" ></td>
</tr>
<tr>
<th>ํ์์ฃผ์</th>
<td><input type="text" name="address" ></td>
</tr>
<tr>
<th>๊ฐ์
์ผ์</th>
<td><input type="text" name="joindate" ></td>
</tr>
<tr>
<th>๊ณ ๊ฐ๋ฑ๊ธ[A:VIP,B:์ผ๋ฐ,C:์ง์]</th>
<td><input type="text" name="grade" ></td>
</tr>
<tr>
<th>๋์์ฝ๋</th>
<td><input type="text" name="city" ></td>
</tr>
<tr>
<td colspan="2">
<button class="btn" type="submit" onclick="fn_submit(); return false;">๋ฑ ๋ก</button>
<button class="btn" type="button" onclick="location='list'">์กฐ ํ</button>
</td>
</tr>
</table>
</div>
</form>
</section>
<%@ include file="footer.jsp" %>
</body>
</html>
list.jsp (ํ์๋ชฉ๋ก์กฐํ/์์ )
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "DTO.Member" %>
<%
request.setCharacterEncoding("UTF-8");
ArrayList<Member>list = new ArrayList<Member>();
list = (ArrayList<Member>)request.getAttribute("list");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
<link rel="stylesheet" href="style.css?ver=1">
</head>
<body>
<%@ include file="topmenu.jsp" %>
<section>
<div class="title">
์ผํ๋ชฐ ํ์๊ด๋ฆฌ ํ๋ก๊ทธ๋จ
</div>
<div class="wrapper">
<table style="width:900px">
<tr>
<th>ํ์๋ฒํธ</th>
<th>ํ์์ฑ๋ช
</th>
<th>์ ํ๋ฒํธ</th>
<th>์ฃผ์</th>
<th>๊ฐ์
์ผ์</th>
<th>๊ณ ๊ฐ๋ฑ๊ธ</th>
<th>๊ฑฐ์ฃผ์ง์ญ</th>
<th>์ญ์ </th>
</tr>
<%for(int i=0; i<list.size(); i++){ %>
<tr>
<td><a href="modify?custno=<%=list.get(i).getCustno() %>">
<%=list.get(i).getCustno() %></a></td>
<td><%=list.get(i).getCustname() %></td>
<td><%=list.get(i).getPhone() %></td>
<td><%=list.get(i).getAddress() %></td>
<td><%=list.get(i).getJoindate() %></td>
<td><%=list.get(i).getGrade() %></td>
<td><%=list.get(i).getCity() %></td>
<td><a href="delete?custno=<%=list.get(i).getCustno() %>">
Delete</a></td>
</tr>
<%}%>
</table>
</div>
</section>
<%@ include file="footer.jsp" %>
</body>
</html>
result.jsp (ํ์๋งค์ถ์กฐํ)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "DTO.Money" %>
<%
request.setCharacterEncoding("UTF-8");
ArrayList<Money>list = new ArrayList<Money>();
list = (ArrayList<Money>)request.getAttribute("list");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
<link rel="stylesheet" href="style.css?ver=1">
</head>
<body>
<%@ include file="topmenu.jsp" %>
<section>
<div class="title">
ํ์๋งค์ถ์กฐํ
</div>
<div class="wrapper">
<table>
<tr>
<th>ํ์๋ฒํธ</th>
<th>ํ์์ฑ๋ช
</th>
<th>๊ณ ๊ฐ๋ฑ๊ธ</th>
<th>๋งค์ถ</th>
</tr>
<%
for(int i=0; i<list.size(); i++){
%>
<tr>
<td><%=list.get(i).getCustno() %></td>
<td><%=list.get(i).getCustname() %></td>
<td><%=list.get(i).getGrade() %></td>
<td><%=list.get(i).getPrice() %></td>
</tr>
<%}%>
</table>
</div>
</section>
<%@ include file="footer.jsp" %>
</body>
</html>
modify.jsp (ํ์์์ )
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="DTO.Member" %>
<%
request.setCharacterEncoding("UTF-8");
ArrayList<Member>list = new ArrayList<Member>();
list = (ArrayList<Member>)request.getAttribute("list");
int custno = list.get(0).getCustno();
String custname = list.get(0).getCustname();
String phone = list.get(0).getPhone();
String address = list.get(0).getAddress();
String joindate = list.get(0).getJoindate();
String grade = list.get(0).getGrade();
String city = list.get(0).getCity();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css?ver=1">
</head>
<body>
<%@ include file="topmenu.jsp" %>
<section>
<div class="title">
ํ์ผํ ํ์ ์ ๋ณด ์์
</div>
<form name="frm" action="update">
<input type="hidden" id="GUBUN" value="update" >
<div class="wrapper">
<table>
<tr>
<th>ํ์๋ฒํธ(์๋๋ฐ์)</th>
<td><input name="custno" value="<%=custno %>" readonly value="1"></td>
</tr>
<tr>
<th>ํ์์ฑ๋ช
</th>
<td><input type="text" name="custname" value="<%=custname%>"></td>
</tr>
<tr>
<th>ํ์์ ํ</th>
<td><input type="text" name="phone" value="<%=phone%>"></td>
</tr>
<tr>
<th>ํ์์ฃผ์</th>
<td><input type="text" name="address" value="<%=address%>"></td>
</tr>
<tr>
<th>๊ฐ์
์ผ์</th>
<td><input type="text" name="joindate" value="<%=joindate%>"></td>
</tr>
<tr>
<th>๊ณ ๊ฐ๋ฑ๊ธ[A:VIP,B:์ผ๋ฐ,C:์ง์]</th>
<td><input type="text" name="grade" value="<%=grade%>"></td>
</tr>
<tr>
<th>๋์์ฝ๋</th>
<td><input type="text" name="city" value="<%=city%>"></td>
</tr>
<tr>
<td colspan="2">
<button class="btn" type="submit" onclick="fn_submit(); return false;">์ ์ </button>
<button class="btn" type="button" onclick="location='list'">์กฐ ํ</button>
</td>
</tr>
</table>
</div>
</form>
</section>
<%@ include file="footer.jsp" %>
</body>
</html>
topmenu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<header>
์ผํ๋ชฐ ํ์๊ด๋ฆฌ ver 1.0
</header>
<nav>
<ul>
<li><a href="add">ํ์๋ฑ๋ก</a></li>
<li><a href="list">ํ์๋ชฉ๋ก์กฐํ/์์ </a></li>
<li><a href="result">ํ์๋งค์ถ์กฐํ</a></li>
<li><a href="home">ํ์ผ๋ก</a></li>
</ul>
</nav>
</body>
</html>
footer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<footer>
HRDKOREA Copyright@2016 All rights reserved. Human Resources Development Service of Korea
</footer>
</body>
</html>
style.css
@charset "UTF-8";
*{
margin: 0;
padding: 0;
}
body{
font-family: gulim;
}
header{
top: 0;
height: 150px;
line-height: 150px;
width: 100%;
background: #333;
text-align: center;
font-size: 35px;
font-weight: 900;
color: #fff;
}
nav ul{
height: 50px;
line-height: 50px;
width: 100%;
background: #444;
}
nav ul li{
list-style: none;
float: left;
padding: 0 10px;
}
a{
text-decoration: none;
color: #fff;
}
a:hover{
cursor: pointer;
opacity: 0.3;
}
section{
position: absolute;
overflow: auto;
width: 100%;
height: 100%;
background: #e3e5e5;
}
.main{
margin: 0 2rem;
}
.main ul li{
list-style: number;
}
.title{
font-size: 30px;
font-weight: 900;
text-align: center;
margin: 3rem;
}
.wrapper{
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
table{
width: 600px;
}
table,tr,th,td{
border: 1px solid #333;
border-collapse: collapse;
padding: 0.7rem;
}
td input{
float: left;
padding: 0.3rem;
}
.btn{
padding: 0.4rem 1rem;
border-radius: 0.4rem;
border: 0;
}
.btn:hover{
opacity: 0.6;
cursor: pointer;
}
footer{
position: fixed;
bottom: 0;
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
background: #333;
}
script.js
function fn_submit(){
var fn = document.frm;
if(fn.custname.value == ""){
alert("ํ์์ฑ๋ช
์ด ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.custname.focus();
return false;
}
if(fn.phone.value == ""){
alert("ํ์์ ํ๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.phone.focus();
return false;
}
if(fn.address.value == ""){
alert("ํ์์ฃผ์๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.address.focus();
return false;
}
if(fn.joindate.value == ""){
alert("๊ฐ์
์ผ์๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.joindate.focus();
return false;
}
if(fn.grade.value == ""){
alert("๊ณ ๊ฐ๋ฑ๊ธ์ด ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.grade.focus();
return false;
}
if(fn.city.value == ""){
alert("๋์์ฝ๋๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
fn.city.focus();
return false;
}
fn.submit();
}
( ๋ฐ์ดํฐ๋ฒ ์ด์ค ๐๐ป ์๋ฒ ๐๐ป ํ๋ก ํธ ๐๐ป ๋ฐฑ์๋ ) [ OPEN ]
DAO/MemberDAO.java
package DAO;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DTO.Member;
import DTO.Money;
public class MemberDAO {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
public static Connection getConnection() throws Exception{
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@//localhost:1521/xe","system","1234");
return con;
}
public String nextCustno(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
conn = getConnection();
// ํ์๋ฒํธ+1 ๊ฐ์ ธ์ค๊ธฐ
String sql = "SELECT max(custno)+1 custno FROM member_tbl_02";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
int custno = 0;
if(rs.next()) custno = rs.getInt(1);
request.setAttribute("custno", custno);
conn.close();
ps.close();
rs.close();
}catch(Exception e) {
e.printStackTrace();
}
return "add.jsp";
}
public String selectAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArrayList<Member>list = new ArrayList<Member>();
try {
conn = getConnection();
// ํ์๋ฆฌ์คํธ ๊ฐ์ ธ์ค๊ธฐ
String sql = " SELECT ";
sql+= " custno, ";
sql+= " custname, ";
sql+= " phone, ";
sql+= " address, ";
sql+= " TO_CHAR(joindate,'YYYY-MM-DD') joindate, ";
sql+= " DECODE(grade,'A','VIP','B','์ผ๋ฐ','์ง์') grade, ";
sql+= " city ";
sql+= " FROM member_tbl_02 ";
sql+= " ORDER BY custno";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()) {
Member member = new Member();
member.setCustno(rs.getInt(1));
member.setCustname(rs.getString(2));
member.setPhone(rs.getString(3));
member.setAddress(rs.getString(4));
member.setJoindate(rs.getString(5));
member.setGrade(rs.getString(6));
member.setCity(rs.getString(7));
list.add(member);
}
request.setAttribute("list",list);
conn.close();
ps.close();
rs.close();
}catch(Exception e) {
e.printStackTrace();
}
return "list.jsp";
}
public String modify(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArrayList<Member>list = new ArrayList<Member>();
try {
conn = getConnection();
int custno = Integer.parseInt(request.getParameter("custno"));
// ์์ ํ ํ์์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
String sql = " SELECT ";
sql+= " custname, ";
sql+= " phone, ";
sql+= " address, ";
sql+= " TO_CHAR(joindate,'YYYY-MM-DD') joindate, ";
sql+= " grade, ";
sql+= " city ";
sql+= " FROM member_tbl_02 WHERE custno ="+custno;
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next()) {
Member member = new Member();
member.setCustno(custno);
member.setCustname(rs.getString(1));
member.setPhone(rs.getString(2));
member.setAddress(rs.getString(3));
member.setJoindate(rs.getString(4));
member.setGrade(rs.getString(5));
member.setCity(rs.getString(6));
list.add(member);
}
request.setAttribute("list",list);
request.setAttribute("custno", custno);
conn.close();
ps.close();
rs.close();
}catch(Exception e) {
e.printStackTrace();
}
return "modify.jsp";
}
public String selectResult(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArrayList<Money>list = new ArrayList<Money>();
try {
conn = getConnection();
// ํ์๋ฒํธ+1 ๊ฐ์ ธ์ค๊ธฐ
String sql = "SELECT ";
sql+= "m1.custno, ";
sql+= "m1.custname, ";
sql+= "DECODE(m1.grade,'A','VIP','B','์ผ๋ฐ','์ง์')grade, ";
sql+= "SUM(m2.price)price ";
sql+= "FROM member_tbl_02 m1, money_tbl_02 m2 ";
sql+= "WHERE m1.custno = m2.custno ";
sql+= "GROUP BY (m1.custno, m1.custname, grade) ";
sql+= "ORDER BY price DESC";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()) {
Money money = new Money();
money.setCustno(rs.getInt(1));
money.setCustname(rs.getString(2));
money.setGrade(rs.getString(3));
money.setPrice(rs.getInt(4));
list.add(money);
}
request.setAttribute("list", list);
conn.close();
ps.close();
rs.close();
}catch(Exception e) {
e.printStackTrace();
}
return "result.jsp";
}
public String insert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int custno = Integer.parseInt(request.getParameter("custno"));
String custname = request.getParameter("custname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String joindate = request.getParameter("joindate");
String grade = request.getParameter("grade");
String city = request.getParameter("city");
int result = 0;
try {
conn = getConnection();
// prepareStatement๋ ์์์ ๋ฐ๋ผ ๊ฐ์ด ๋ฑ๋ก๋๋ค.
String sql = "INSERT INTO member_tbl_02 VALUES(?,?,?,?,TO_DATE(?,'YYYY-MM-DD'),?,?)";
ps = conn.prepareStatement(sql);
ps.setInt(1, custno);
ps.setString(2, custname);
ps.setString(3, phone);
ps.setString(4, address);
ps.setString(5, joindate);
ps.setString(6, grade);
ps.setString(7, city);
result = ps.executeUpdate();
System.out.println(result);
conn.close();
ps.close();
}catch(Exception e) {
e.printStackTrace();
}
return "add";
}
public int update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int custno = Integer.parseInt(request.getParameter("custno"));
String custname = request.getParameter("custname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String joindate = request.getParameter("joindate");
String grade = request.getParameter("grade");
String city = request.getParameter("city");
int result = 0;
try {
conn = getConnection();
String sql = "UPDATE member_tbl_02 SET";
sql+= " custname = ? , ";
sql+= " phone = ? , ";
sql+= " address = ? , ";
sql+= " joindate = TO_DATE(?,'YYYY-MM-DD'), ";
sql+= " grade = ? , ";
sql+= " city = ? ";
sql+= " WHERE custno = ? ";
ps = conn.prepareStatement(sql);
ps.setString(1, custname);
ps.setString(2, phone);
ps.setString(3, address);
ps.setString(4, joindate);
ps.setString(5, grade);
ps.setString(6, city);
ps.setInt(7, custno);
result = ps.executeUpdate();
conn.close();
ps.close();
}catch(Exception e) {
e.printStackTrace();
}
return result;
}
public int delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int result = 0;
try {
conn = getConnection();
String custno = request.getParameter("custno");
String sql = "DELETE FROM member_tbl_02 WHERE custno="+custno;
ps = conn.prepareStatement(sql);
result = ps.executeUpdate();
conn.close();
ps.close();
}catch(Exception e) {
e.printStackTrace();
}
return result;
}
}
warfile ๋ค์ด๋ก๋
war ํ์ผ ์ดํด๋ฆฝ์ค์์ import ํ๊ธฐ ( ์ค๋ฅธ์ชฝ๋ง์ฐ์ค -> import -> war file -> war file ๋ถ๋ฌ์ค๊ธฐ -> finish )