JSP 오라클 ResultSet

JAVA/JSP 2015. 8. 24. 16:39

<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<%@page import="java.sql.*"%>

<%@page import="javax.sql.*"%>

<%@page import="javax.naming.*"%>

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

</head>

<body>

<%

Connection con = null;

String sql = "select * from test";

String[] arr = { "홈길동", "뽀로로", "배트맨" };

try {


Context init = new InitialContext();

DataSource ds =(DataSource)init.lookup("java:comp/env/jdbc/OracleDB");

con = ds.getConnection();


PreparedStatement pstmt = con.prepareStatement(sql);

ResultSet re = pstmt.executeQuery();


while(re.next()){

out.println("<h3>"+re.getInt(1)+" "+re.getString(2)+"</h3>");

}


            //모든 자원 close();


} catch (Exception e) {

out.println("<h2>연결실패하였습니다..</h2>");

e.printStackTrace();


}

%>


</body>

</html>

'JAVA > JSP' 카테고리의 다른 글

JSP 파일업로드 폼  (0) 2015.08.25
JSP 오라클 트랜잭션  (0) 2015.08.24
JSP 오라클 Statement  (0) 2015.08.21
JSP 오라클 PreparedStatement  (0) 2015.08.21
JSP 커넥션풀 속성  (0) 2015.08.21
블로그 이미지

왕왕왕왕

,