티스토리 뷰
반응형
1. MySQL 5.x용 JDBC 드라이버
mysql-connector-java-5.1.25-bin.jar
2. viewMemberList.jsp
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>회원 목록</title>
</head>
<body>
<caption>Member 테이블의 내용</caption>
<table width="100%" border="1">
<thead>
<tr>
<th>이름</th>
<th>아이디</th>
<th>이메일</th>
</tr>
</thead>
<tbody>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
String jdbcDriver = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
String dbUser = "test";
String dbPwd = "test";
conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPwd);
pstmt = conn.prepareStatement("select * from ez_member");
rs = pstmt.executeQuery();
while(rs.next()){
%>
<tr>
<td><%= rs.getString("name") %></td>
<td><%= rs.getString("id") %></td>
<td><%= rs.getString("email") %></td>
</tr>
<%
}
}catch(SQLException se){
se.printStackTrace();
}finally{
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
}
%>
</tbody>
</table>
</body>
</html>
반응형
'Web Dev > JSP' 카테고리의 다른 글
| [JSP] DBCP를 이용한 커넥션 풀(Connection Pool) 사용하기. (0) | 2013.06.05 |
|---|---|
| [JSP] MySQL jdbcDriver 자동로드 및 트랜잭션 처리하기. (0) | 2013.06.05 |
| [JSP] 세션시간 설정하기 (0) | 2013.06.04 |
| [JSP] jsp:include 와 include 디렉티브의 차이 (0) | 2013.06.04 |
| [JSP] 코드 조각 자동 포함시키기 (0) | 2013.06.04 |
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Oracle
- 항공편
- MySQL
- asp
- Drop
- regexp
- 실시간
- ready
- create
- jsp
- attr
- 제이쿼리
- select
- Filter
- 인천공항
- 기초
- centOS
- Click
- android
- Next
- dom
- event
- Selector
- If
- jquery
- html
- javascript
- submit
- 비행기
- focus
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함