<%@page import="java.util.Vector"%>
<%@page import="member.MemberDAO"%>
<%@page import="member.MemberBean"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Member List</title>
</head>
<body>
<center>
<h2>Member List</h2>
<table cellpadding="5" border="1" bordercolor="white" bgcolor="#FFBB00" width="400" >
<tr>
<td>No.</td>
<td>ID</td>
<td>Name</td>
<td>Gender</td>
<td>Phone</td>
<td>E-mail</td>
</tr>
<%
MemberDAO mdao = new MemberDAO();
MemberBean mbean = new MemberBean();
Vector<MemberBean> vector = mdao.getAllMember();
for(int i=0; i<vector.size(); i++)
{
mbean = vector.get(i);
%>
<tr bgcolor="white">
<td><%= i+1 %></td>
<td>
<a href="MemberInfo.jsp?id=<%=mbean.getId()%>"><%=mbean.getId()%></a>
</td>
<td><%= mbean.getName() %></td>
<td><%= mbean.getGender() %></td>
<td><%= mbean.getPhone() %></td>
<td><%= mbean.getEmail() %></td>
</tr>
<%
}
%>
</table>
<br>
<a href = "MemberForm.jsp"> Member Join </a>
</center>
</body>
</html>
result)
MemberForm.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=EUC-KR">
<title>Member Join</title>
</head>
<body>
<center>
<h2>Member Join</h2>
<form action="MemberJDBC.jsp" method="post">
<table cellpadding="5" border="1" bordercolor="white" bgcolor="#FFBB00">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
</tr>
<tr>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
<th>E-mail</th>
<th><input type="text" name="email" size="16"></th>
</tr>
<tr>
<th>Phone</th>
<th><input type="text" name="phone" size="16"></th>
<th>Address</th>
<th><input type="text" name="address" size="16"></th>
<tr>
<th>Gender</th>
<th><input type="radio" name="gender" value="male"> male
<input type="radio" name="gender" value="female"> female</th>
<th>Hobby</th>
<th><input type="checkbox" name="hobby1" value="baseball">baseball
<input type="checkbox" name="hobby2" value="soccer">soccer</th>
</tr>
<tr>
<th>etc</th>
<th colspan="3"><textarea name="etc" rows="3" cols="50"></textarea></th>
<tr>
<th colspan="4">
<center>
<input type="submit" value="Send">
<input type="reset" value="Cancel">
</center>
</th>
</tr>
</table>
</form>
</center>
</body>
</html>
MemberJDBC.jsp
<%@page import="member.MemberDAO"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>jdbc</title>
</head>
<body>
<jsp:useBean id="mbean" class="member.MemberBean"/>
<jsp:setProperty property="*" name="mbean"/>
<%
MemberDAO mdao = new MemberDAO();
mdao.con();
mdao.insertMember(mbean);
response.sendRedirect("MemberList.jsp");
%>
</body>
</html>
result)
MemberInfo.jsp
<%@page import="member.MemberBean"%>
<%@page import="java.util.Vector"%>
<%@page import="member.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Member Information</title>
</head>
<body>
<center>
<%
MemberDAO mdao = new MemberDAO();
MemberBean mbean = new MemberBean();
mbean = mdao.getSelectMember(request.getParameter("id"));
%>
<h2>Member Information</h2>
<table border="1" bordercolor="white" bgcolor="#FFBB00" cellpadding="5">
<form action="MemberUpdate.jsp" method = "post">
<tr>
<td>ID</td>
<td>
<input type="text" name=id value=<%=mbean.getId()%>>
</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input type="text" name=phone value=<%=mbean.getPhone()%>>
</td>
</tr>
<tr>
<td>E-mail</td>
<td>
<input type="text" name=email value=<%=mbean.getEmail()%>>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="submit" value="Update">
</td>
</tr>
</form>
<tr>
<td colspan="4" align="center">
<form action = "MemberDelete.jsp?id=<%=mbean.getId()%>" method = "post">
<input type="submit" value="Delete">
</form>
</td>
</tr>
</table>
</center>
</body>
</html>
MemberUpdate.jsp
<%@page import="member.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Member Update</title>
</head>
<body>
<%
MemberDAO mdao = new MemberDAO();
mdao.updateMember(request.getParameter("id"),
request.getParameter("phone"),
request.getParameter("email"));
response.sendRedirect("MemberList.jsp");
%>
</body>
</html>
result)
MemberDelete.jsp
<%@page import="member.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Member Delete</title>
</head>
<body>
<%
MemberDAO mdao = new MemberDAO();
mdao.deleteMember(request.getParameter("id"));
response.sendRedirect("MemberList.jsp");
%>
</body>
</html>
MemberBean.java
package member;
public class MemberBean
{
private String id;
private String password;
private String name;
private String email;
private String gender;
private String hobby1;
private String hobby2;
private String phone;
private String address;
private String etc;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getHobby1() {
return hobby1;
}
public void setHobby1(String hobby1) {
this.hobby1 = hobby1;
}
public String getHobby2() {
return hobby2;
}
public void setHobby2(String hobby2) {
this.hobby2 = hobby2;
}
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 getEtc() {
return etc;
}
public void setEtc(String etc) {
this.etc = etc;
}
}
MemberDAO.java
package member;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
public class MemberDAO
{
String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;
public void con()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}
public void insertMember(MemberBean mbean)
{
this.con();
String sql = "INSERT into member values(?,?,?,?,?,?,?,?,?,?)";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, mbean.getId());
ps.setString(2, mbean.getPassword());
ps.setString(3, mbean.getName());
ps.setString(4, mbean.getEmail());
ps.setString(5, mbean.getGender());
ps.setString(6, mbean.getHobby1());
ps.setString(7, mbean.getHobby2());
ps.setString(8, mbean.getPhone());
ps.setString(9, mbean.getAddress());
ps.setString(10, mbean.getEtc());
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e)
{
}
}
public Vector<MemberBean> getAllMember()
{
Vector<MemberBean> vector = new Vector<>();
MemberBean mbean;
try
{
this.con();
String sql = "SELECT * from member";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next())
{
mbean = new MemberBean();
mbean.setId(rs.getString(1));
mbean.setPassword(rs.getString(2));
mbean.setName(rs.getString(3));
mbean.setEmail(rs.getString(4));
mbean.setGender(rs.getString(5));
mbean.setHobby1(rs.getString(6));
mbean.setHobby2(rs.getString(7));
mbean.setPhone(rs.getString(8));
mbean.setAddress(rs.getString(9));
mbean.setEtc(rs.getString(10));
vector.add(mbean);
}
con.close();
ps.close();
rs.close();
}
catch(Exception e)
{
}
return vector;
}
public void updateMember(String id, String phone, String email)
{
this.con();
String sql = "UPDATE member set phone=?, email=? where id=?";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, phone);
ps.setString(2, email);
ps.setString(3, id);
ps.executeUpdate();
ps.close();
con.close();
}
catch (Exception e)
{
}
}
public void deleteMember(String id)
{
this.con();
String sql="DELETE from member where id=?";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, id);
ps.executeUpdate();
ps.close();
con.close();
}
catch (Exception e)
{
}
}
public MemberBean getSelectMember(String id)
{
this.con();
MemberBean member = new MemberBean();
String sql = "SELECT * from member where id=?";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
rs.next();
member.setId(rs.getString(1));
member.setEmail(rs.getString(4));
member.setPhone(rs.getString(8));
con.close();
ps.close();
rs.close();
}
catch(Exception e)
{
}
return member;
}
}
result)
댓글 없음:
댓글 쓰기