<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.sun.xml.internal.ws.api.ha.StickyFeature"%>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("dong") == null){
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>zipsearch_02</title>
<script type="text/javascript">
function checkfrm() {
if(document.frm.dong.value == ""){
alert("동이름을 입력하세요");
return;
}
document.frm.submit();
}
</script>
</head>
<body>
<form name="frm" method="post" action="zipsearch_02.jsp">
<table border="1">
<tr>
<td colspan="2">동 이름 검색</td>
</tr>
<tr>
<td> <input type="text" name="dong" size="20" value="개포1동" /> </td>
<td> <input type="button" value="검색" onclick="checkfrm()" /> </td>
</tr>
</table>
</form>
</body>
</html>
<%
} else{
String dong = request.getParameter("dong");
Connection conn =null;
Statement stmt = null;
ResultSet rs = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "hr");
String query = "select * from zipcode where DONG like '" + dong + "%'";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
%>
<html>
<head>
<meta charset="UTF-8">
<title>zipsearch_02</title>
<style type="text/css">
td {border: 1px solid black; width: 150px ; text-align: center;}
</style>
</head>
<!-- -->
<body>
<table>
<%
out.println("<tr>");
out.println("<td><b>일련번호</b></td>");
out.println("<td><b>우편번호</b></td>");
out.println("<td><b>시.도</b></td>");
out.println("<td><b>구.군</b></td>");
out.println("<td><b>동</b></td>");
out.println("<td><b>리</b></td>");
out.println("<td><b>앞번지</b></td>");
out.println("<td><b>뒷번지</b></td>");
out.println("</tr>");
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString("seq") + "</td>");
out.println("<td>" + rs.getString("zipcode") + "</td>");
out.println("<td>" + rs.getString("sido") + "</td>");
out.println("<td>" + rs.getString("gugun") + "</td>");
out.println("<td>" + rs.getString("dong") + "</td>");
//null값 처리
String ri = rs.getString("ri") == null ? "" : rs.getString("ri");
String st_bunji = rs.getString("st_bunji") == null ? "" : rs.getString("st_bunji");
String ed_bunji = rs.getString("ed_bunji") == null ? "" : rs.getString("ed_bunji");
out.println("<td>" + ri + "</td>");
out.println("<td>" + st_bunji + "</td>");
out.println("<td>" + ed_bunji + "</td>");
out.println("</tr>");
}
%>
<tr>
<td colspan="8"> <input type="button" value="뒤로가기" onclick="history.back()"/> </td>
</tr>
</table>
</body>
</html>
<%
}
%>
입력화면
검색결과
'JAVA > JSP & Servlet' 카테고리의 다른 글
톰캣에서 JSP 데이터베이스 커넥션 풀 사용하기 (context, 풀링) (0) | 2013.03.14 |
---|---|
[이클립스] JSP에서 IP제대로 출력되게 하기 ( -Djava.net.preferIPv4Stack=true) (0) | 2013.03.13 |
JSP : 우편번호검색 페이지 (0) | 2013.03.08 |
JSP 기본 실습 : ==데이터베이스 연결 (JDBC)== (0) | 2013.03.08 |
JSP 기본 실습 : 입출력 BufferedReader (2) | 2013.03.08 |