<%@page import="org.apache.jasper.tagplugins.jstl.core.Catch"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@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>::: JSP_JDBC_EX ::::</title>
</head>
<body>
MEMBER 테이블의 내용
<table width="100" border="1">
<tr>
<td>이름</td>
<td>아이디</td>
<td>이메일</td>
</tr>
<%
/* 1.JDBC 드라이버 로딩(등록) */
Class.forName("oracle.jdbc.OracleDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String jdbcDriver = "jdbc:oracle:thin:@localhost:1521:XE";
/* jdbc:oracle:thin:@hostid:port:SID */
String dbUser = "HR";
String dbPass = "HR";
String query = "SELECT * FROM MEMBER ORDER BY MEMBERID";
/* 2.데이터 베이스 커넥션 생성 */
conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
/* 3.Statement 생성 */
stmt = conn.createStatement();
/* 4.쿼리실행 */
rs = stmt.executeQuery(query); // SELECT
// executeUpdate - INSERT, UPDATE, DELETE ( RETURN 값 - INT )
/* 5.쿼리 실행 결과 출력 */
while(rs.next() ) {
%>
<tr>
<td><%= rs.getString("NAME") %></td>
<td><%= rs.getString("MEMBERID") %></td>
<td><%= rs.getString("EMAIL") %></td>
</tr>
<%
}
} catch (SQLException ex) {
out.println(ex.getMessage() );
ex.printStackTrace();
} finally {
/* 6.사용한 Statement 종료 */
if ( rs != null )
try {
rs.close();
} catch (SQLException ex) {}
if ( stmt != null )
try {
stmt.close();
} catch (SQLException ex) {}
/* 7.커넥션 종료 */
if ( conn != null )
try {
conn.close();
} catch (SQLException ex) {}
}
%>
</table>
</body>
</html>
'공부 > JSP' 카테고리의 다른 글
JSP_[웹 어플리케이션의 초기화 파라미터 값 설정] (0) | 2012.09.19 |
---|---|
JSP_[JSP 페이지의 초기화 파라미터] (0) | 2012.09.18 |
JSP_[Request_기본객체] (0) | 2012.06.21 |
JSP_[페이지 읽어올때 캐릭터셋 결정 기본과정] (0) | 2012.06.21 |
JSP_[페이지의 구성요소] (0) | 2012.06.21 |