관리 메뉴

moozi

oracle jdbc 샘플 본문

TIS_2017/응용sw_1기

oracle jdbc 샘플

moozi 2017. 3. 23. 10:57

<%@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"%>

<%!//선언부는 첫 방문자에 의해서 단 한번 수행합니다.

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

String url = "jdbc:oracle:thin:@localhost:1521:orcl";

String uid = "hr";

String pass = "1234";

String sql = "select * from members";%>

<!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>Insert title here</title>

</head>

<body>

<table width='800' border='1'>

<tr>

<th>이름</th>

<th>아이디</th>

<th>암호</th>

<th>이메일</th>

<th>전화번호</th>

<th>권한(1:관리자, 2:일반회원)</th>

</tr>

<%

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection(url, uid, pass);

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

while (rs.next()) {

out.println("<tr>");

out.println("<td>" + rs.getString("name") + "</td>");

out.println("<td>" + rs.getString("userid") + "</td>");

out.println("<td>" + rs.getString("pwd") + "</td>");

out.println("<td>" + rs.getString("email") + "</td>");

out.println("<td>" + rs.getString("phone") + "</td>");

out.println("<td>" + rs.getInt("admin") + "</td>");

out.println("</tr>");

}//while의 끝

} catch (Exception e) {

out.println(e.getMessage());

//e.printStackTrace();

} finally {

try {

if (rs != null)

rs.close();

if (stmt != null)

stmt.close();

if (conn != null)

conn.close();

} catch (Exception e) {

e.printStackTrace();

}

}//finally의 끝

%>

</table>

</body>

</html>

'TIS_2017 > 응용sw_1기' 카테고리의 다른 글

비밀번호 암호화 처리  (0) 2017.03.27
jspConn04 post처리  (0) 2017.03.24
버스 위치 추적  (0) 2017.03.22
key  (0) 2017.03.22
sample mp4  (0) 2017.03.21
Comments