ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

PROGRAMMING

java dbcp

๐Ÿ”ฅ fire 2010. 6. 29. 19:28

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





'PROGRAMMING' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

jsp EL  (0) 2010.07.06
์ผ๋‹จ, ์•ˆ๋“œ๋กœ์ด๋“œ ๊ฐœ๋ฐœ์ž ๋“ฑ๋ก  (0) 2010.07.06
๋ฆฌ๋ˆ…์Šค alias, pplog, pprestart  (0) 2010.06.29
jsp ์—๋ŸฌํŽ˜์ด์ง€ ์ง€์ •  (0) 2010.06.22
sqlinform.com/online.phtml  (0) 2010.06.16
๋Œ“๊ธ€