|
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 | <% |
|---|
| 11 | Class.forName("com.mysql.jdbc.Driver").newInstance(); |
|---|
| 12 | String uri="jdbc:mysql://localhost/mydb?characterEncoding=UTF-8"; |
|---|
| 13 | Connection conn = DriverManager.getConnection(uri,"test","pass"); |
|---|
| 14 | String zip=request.getParameter("zip"); |
|---|
| 15 | |
|---|
| 16 | PreparedStatement stmt=conn.prepareStatement("SELECT * FROM zips WHERE zip LIKE ?"); |
|---|
| 17 | stmt.setString(1,zip+"%"); |
|---|
| 18 | |
|---|
| 19 | stmt.setMaxRows(100); |
|---|
| 20 | ResultSet rs=stmt.executeQuery(); |
|---|
| 21 | |
|---|
| 22 | out.print("<ul>"); |
|---|
| 23 | while (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>"); |
|---|
| 32 | out.print("</ul>"); |
|---|
| 33 | %> |
|---|
| 34 | </body> |
|---|
| 35 | </html> |
|---|