./categories/server
Tomcat DBCP Oracle Connection Pool
1) context.xml DataSource
<Resource name="jdbc/dbcp" auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@DB_URL:DB_PORT:DB_SID"
username="NAME" password="PASS"
maxActive="20" maxIdle="10" maxWait="-1"/>
2) web.xml 리소스 참조
<resource-ref>
<description>Oracle11g</description>
<res-ref-name>jdbc/dbcp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3) Java에서 lookup
public class DbcpConnection {
public Connection getConnection() {
Connection con = null;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/dbcp");
con = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
관련 링크: https://sewsky.tistory.com/1
./comments