<!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>Introduce GUI</title>
</head>
<body>
<form action="jdbc.jsp" method="post">
<table cellpadding="5">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
</tr>
<tr>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
</tr>
<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="hobby" value="baseball">baseball
<input type="checkbox" name="hobby" value="soccer">soccer</th>
</tr>
<tr>
<th>Phone</th>
<th><input type="text" name="phone" size="16"></th>
<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="submit" value="Cancel">
</center>
</th>
</tr>
</table>
</form>
</body>
</html>
jdbc.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("Result.jsp");
%>
</body>
</html>
Result.jsp
<%@ 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>Result</title>
</head>
<body>
<h2> 입력 완료 </h2>
<a href = "form.jsp"> 뒤로 </a>
</body>
</html>
MemberBean.java
package member;
public class MemberBean
{
private String id;
private String password;
private String name;
private String gender;
private String hobby;
private String phone;
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 getGender()
{
return gender;
}
public void setGender(String gender)
{
this.gender = gender;
}
public String getHobby()
{
return hobby;
}
public void setHobby(String hobby)
{
this.hobby = hobby;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
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;
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 membertest 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.getGender());
ps.setString(5, mbean.getHobby());
ps.setString(6, mbean.getPhone());
ps.setString(7, mbean.getEtc());
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e)
{
}
}
}
result)
댓글 없음:
댓글 쓰기