DBCP : http://commons.apache.org/dbcp/downloads.html
Pool : http://commons.apache.org/pool/downloads.html
Collection : http://commons.apache.org/downloads/download_collections.cgi
<object class="org.apache.commons.dbcp.PoolableConnectionFactory"
xmlns="http://apache.org/xml/xmlns/jakarta/commons/jocl">
<object class="org.apache.commons.dbcp.DriverManagerConnectionFactory">
<string value="jdbc:oracle:thin:@taesuz.net:1521:taesuzdb" />
<string value="taesuz" />
<string value="1111" />
</object>
<object class="org.apache.commons.pool.impl.GenericObjectPool">
<object class="org.apache.commons.pool.PoolableObjectFactory" null="true" />
<int value="10" />
<byte value="1" />
<long value="10000" />
<int value="10" />
<int value="3" />
<boolean value="true" />
<boolean value="true" />
<long value="600000" />
<int value="5" />
<long value="3600000" />
<boolean value="true" />
</object>
<object class="org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory" null="true" />
<string null="true" />
<boolean value="false" />
<boolean value="true" />
</object>
package taesuz.dbpool;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import java.util.StringTokenizer;
public class DBCPInit extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
try {
String drivers = config.getInitParameter("pool");
StringTokenizer st = new StringTokenizer(drivers, ",");
while (st.hasMoreTokens()) {
String DB = st.nextToken();
Class.forName(DB);
}
Class.forName("org.apache.commons.dbcp.PoolingDriver");
} catch(Exception ex) {
throw new ServletException(ex);
}
}
}
<web-app>
<servlet>
<servlet-name>DBCPInit</servlet-name>
<servlet-class>taesuz.dbpool.DBCPInit</servlet-class>
<init-param>
<param-name>pool</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
설정 끝~~~~
테스트를 위한 JSP와 커넥션을 가져오는 클래스
package taesuz.dbpool;
import java.sql.*;
public class DBConnect {
/**
* APP/Web 환경에서 쓰이도록 지정 DBCP를 사용한다.
* default poolName : pool
* @return Connection
* @throws SQLException
*/
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:apache:commons:dbcp:/pool");
}
/**
* APP/Web 환경에서 쓰이도록 지정 DBCP를 사용한다.
* @param poolName
* @return Connection
* @throws SQLException
*/
public static Connection getConnection(String poolName) throws SQLException {
return DriverManager.getConnection("jdbc:apache:commons:dbcp:/"
+ poolName);
}
}
<%@ page contentType="text/html;charset=euc-kr" %>
<%@ page import="java.sql.*" %>
<%@ page import="taesuz.dbpool.DBConnect" %>
<%
try{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
conn = DBConnect.getConnection();
String query = "select * from DUAL";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
if(rs.next())
out.print(rs.getString(1));
} catch(Exception e) {
System.out.println(e);
} 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) {}
}
%>
다른 관련 설정 트랙백 참조.
trackback from: Tomcat 에 Oracle DataSource 설정..
답글삭제Download URLDBCP : http://commons.apache.org/dbcp/downloads.htmlPool : http://commons.apache.org/pool/downloads.htmlCollection : http://commons.apache.org/downloads/download_collections.cgi %app_dir%/WEB-INF/web.xml--------------------------------------..
좋은정보 감사합니다. 덕분에 Pool 구현할수 있었습니다.
답글삭제@햄톨 - 2008/07/19 13:09
답글삭제도움이 되었다니 기쁘네요.
즐프하세요~