Tomcat 5.5 Connection Pool 설정
출처 : http://blog.bagesoft.com/725
http://fallacy.tistory.com/76
http://kwon37xi.egloos.com/2852803?89a004e0
1) C:\apache-tomcat-5.5.27\conf\server.xml 내용추가
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:127.0.0.1:1521:orcl"
username="scott" password="tiger" maxActive="20" maxIdle="10"
maxWait="-1"/>
2) C:\apache-tomcat-5.5.27\conf\context.xml 내용추가
<ResourceLink global="jdbc/myoracle" name="jdbc/myoracle" type="javax.sql.DataSource"/>
3) C:\oracle\product\10.2.0\db_1\jdbc\lib 폴더의 ojdbc14.jar 파일을 C:\apache-tomcat-5.5.27\common\lib 폴더에 복사
4) C:\apache-tomcat-5.5.27\webapps\ROOT\WEB-INF\web.xml 내용 추가
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
5) Tomcat 재실행
6) 테스트 JSP 파일 작성
<%@ page import="java.sql.*, javax.naming.*, javax.sql.*"%>
<%
Context initCtx = new InitialContext();
/*
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
*/
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/myoracle");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
stmt = conn.createStatement();
String query = "select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') from dual"; // 현재 시간을 구하는 query
rs = stmt.executeQuery(query);
if(rs.next()) {
out.println("<br>" + rs.getString(1));
}
} catch (Exception e) {
out.println("<br>" + e.toString());
} finally {
if (rs!=null) try { rs.close(); } catch (Exception e) { }
if (stmt!=null) try { stmt.close(); } catch (Exception e) { }
if (conn!=null) try { conn.close(); } catch (Exception e) { }
}
%>