<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>jdbcTest.jsp</title>
</head>
<body>
<H3>JDBC 테스트</H3>
<%
String url = "jdbc:oracle:thin:@localhost:1521:xe";
Connection con = null;
String sql = "select* from dept";
Statement stat = null;
ResultSet rs = null;
try{
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(url, "HR2", "HR2");
stat = con.createStatement();
rs = stat.executeQuery(sql);
out.println("부서코드 부서이름 부서위치"+"<br>"+"<br>");
while(rs.next()){
out.println(rs.getInt("deptno")+" ");
out.println(rs.getString("dname")+" ");
out.println(rs.getString("loc")+"<br>");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(rs!=null)rs.close();
if(stat!=null)stat.close();
if(con!=null)con.close();
}catch(Exception e){}
}
%>
</body>
</html>
결과
OSD 에서 확인
구글 크롬 결과 확인