본문 바로가기

jsp

DB 연동

반응형

a.


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.seoulit.DBUtil3" %>  

<%@ page import="java.sql.*" %> 

<!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>Insert title here</title>

<style type="text/css">

 td { border:2px solid green; }

</style>

</head>

<body>

<form action="b.jsp">

<input type="text" name="id"><br>

<input type="text" name="pw"><br>

<input type="text" name="addr"><br>

<input type="text" name="tel"><br>

<input type="submit" value="가입">

</form>

</body>

</html>



b.


<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<%@ page import="com.seoulit.DBUtil3"%>

<%@ page import="java.sql.*"%>

<!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>Insert title here</title>

<style type="text/css">

td {

border: 2px solid green;

}

</style>

</head>

<body>

<%

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

String pw=request.getParameter("pw");

String addr=request.getParameter("addr");

String tel=request.getParameter("tel");

Connection connection=DBUtil3.getConnection();

PreparedStatement pstmt=connection.prepareStatement("insert into member values(?,?,?,?)");

pstmt.setString(1, id);

pstmt.setString(2, pw);

pstmt.setString(3, addr);

pstmt.setString(4, tel);

pstmt.executeUpdate();

%>

<a href="c.jsp">회원정보리스트</a>

</body>

</html>


c. 


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.seoulit.DBUtil3" %>  

<%@ page import="java.sql.*" %> 

<!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>Insert title here</title>

<style type="text/css">

 td { border:2px solid green; }

</style>

</head>

<body>

<form action="d.jsp">

<%

Connection connection=DBUtil3.getConnection();

Statement stmt=connection.createStatement();

ResultSet rs=stmt.executeQuery("select * from member");

out.write("<table>");

while(rs.next()){

out.write("<tr>");

out.write("<td>");

out.write("<input type=radio name=id value="+rs.getString(1)+"></td>");

out.write("<td>"+rs.getString(1)+"</td>");

out.write("</tr>");

}

out.write("</table>");

%>

<input type="submit" value="회원정보">

</form>

</body>

</html>


d.


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.seoulit.DBUtil3" %>

<%@ page import="java.sql.*" %>

<!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>Insert title here</title>

<style type="text/css">

td {

border: 2px solid green;

}

</style>

</head>

<body>

<%

Connection connection=DBUtil3.getConnection();

String sql="select * from member where id=?";

PreparedStatement pstmt=connection.prepareStatement(sql);

String ename=request.getParameter("id");

pstmt.setString(1, ename);

ResultSet rs=pstmt.executeQuery();

out.write("ID    PW     ADDR    TEL");

out.write("<table>");

if(rs.next()){

out.write("<td>"+rs.getString(1)+"</td>");

out.write("<td>"+rs.getString(2)+"</td>");

out.write("<td>"+rs.getString(3)+"</td>");

out.write("<td>"+rs.getString(4)+"</td></tr>");

}

pstmt.executeUpdate();

%>

</body>

</html>

반응형

'jsp' 카테고리의 다른 글

jquery 꼭 풀어봐야 할 예제들  (0) 2013.11.08
DB연동 회원가입,삭제  (0) 2013.10.31
jsp와 db연동  (0) 2013.10.28
선언문,request객체의메서드들,화면이동하기  (0) 2013.10.23
jsp 1일차 테스트  (0) 2013.10.22