<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*"
import="javax.sql.*"
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>JNDI๋ฅผ ์ด์ฉํ Connection Pool Demo</title>
</head>
<body>
<%
//๋ณ์ ์ค๋น
DataSource ds = null;
Connection con = null;
try{
//๋ค์ด๋ฐ ์๋น์ค์ ์ ๊ทผ
Context ctx = new InitialContext();
//Java ์์์ผ๋ก ์ ๊ทผ
Context envCtx = (Context)ctx.lookup("java:/comp/env");
//์ฐ๋ฆฌ๊ฐ ์ค์ ํ ์์์ ๊ฒ์
ds = (DataSource)envCtx.lookup("jdbc/mysql");
//์ปค๋ฅ์
ํ ๊ฐ์ฒด๋ฅผ ์ฐพ์์ผ๋ ์ปค๋ฅ์
์ ๋น๋ ค์ค์!
con = ds.getConnection();
out.println("con = " + con + "<br/>");
}catch(Exception e){
e.printStackTrace();
out.println(e.getMessage());
}finally{
if(con != null){
//๋น๋ ค์จ ์ปค๋ฅ์
์ ๋ฐ๋์ ๋๋ ค์ฃผ์
con.close();
out.println(con + " closed");
}
}
%>
</body>
</html>