root/trunk/myweb/WebContent/zip.jsp

Revision 51, 1.1 KB (checked in by yabuki, 2 years ago)
  • Property svn:mime-type set to text/plain
Line 
1<?xml version="1.0" encoding="UTF-8" ?>
2<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"%>
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml">
5<head>
6<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
7<title>郵便番号検索結果</title>
8</head>
9<body>
10<%
11Class.forName("com.mysql.jdbc.Driver").newInstance();
12String uri="jdbc:mysql://localhost/mydb?characterEncoding=UTF-8";
13Connection conn = DriverManager.getConnection(uri,"test","pass");
14String zip=request.getParameter("zip");
15
16PreparedStatement stmt=conn.prepareStatement("SELECT * FROM zips WHERE zip LIKE ?");
17stmt.setString(1,zip+"%");
18
19stmt.setMaxRows(100);
20ResultSet rs=stmt.executeQuery();
21
22out.print("<ul>");
23while (rs.next())
24  out.println("<li>"
25    +rs.getString("zip")+": "
26    +rs.getString("addr1")
27    +rs.getString("addr2")
28    +rs.getString("addr3")
29    +rs.getString("addr4")
30    +rs.getString("establishment")
31    +"</li>");
32out.print("</ul>");
33%>
34</body>
35</html>
Note: See TracBrowser for help on using the browser.