일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- MySQL
- sencha touch
- JDOM
- rowspan
- Eclipse
- Google Map
- Spring
- iBATIS
- swingx
- GPS
- phonegap
- WebLogic
- appspresso
- Android
- oracle
- jQuery
- Ajax
- PLSQL
- dock
- tomcat
- MFC
- Struts
- node.js
- 가우스
- jsr 296
- 전자정부프레임워크
- 선택적조인
- PHP
- ibsheet
- JSON
- Today
- Total
Where The Streets Have No Name
USING OC4J CONNECTION POOL 본문
이 글은 Oracle 9i AS 9.0.x이나 Oracle AS 10g 9.0.4.x 내의 OC4J, 또는
OC4J standalone 고객들이 JDBC application을 작성하면서
database connection pool이 필요하거나 다른 connection pool에서 migration할 때 편리하게 활용하시기 위하여 작성되었습니다.
1. configuration file
OC4J의 경우 database connection pool 설정은 config directory 내 data-sources.xml file에서 이루어집니다.
$ORACLE_HOME/j2ee/<OC4J component name>/config/data-sources.xml
예를 들어 OAS 10g에서 OC4J component 중 'home' component에
application을 deploy하시는 경우,
$ORACLE_HOME/j2ee/home/config/data-sources.xml
2. configuration
1) data-sources.xml
예를 들어 다음과 같이 <data-source> tag를 추가해 줍니다.
<?xml version = '1.0' standalone = 'yes'?>
<!DOCTYPE data-sources PUBLIC "Orion data-sources" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
<data-sources>
<!--
An example/default DataSource that uses
Oracle JDBC-driver to create the connections.
This tag creates all the needed kinds
of data-sources, transactional, pooled and EJB-aware sources.
The source generally used in application code is the "EJB"
one - it provides transactional safety and connection
pooling. Oracle thin driver could be used as well,
like below.
url="jdbc:oracle:thin:@host:port:sid"
-->
<data-source class="com.evermind.sql.DriverManagerDataSource"
name="OracleDS" location="jdbc/OracleCoreDS"
xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@localhost:5521:oracle" inactivity-timeout="30"/>
<data-source class="com.evermind.sql.DriverManagerDataSource"
name="DataSource1" location="jdbc/DataSource1"
xa-location="jdbc/xa/DataSource1" ejb-location="jdbc/ejb/DataSource1"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="<username>"
password="<password>"
url="jdbc:oracle:thin:@<IP address of db server>:<port of listener>:<SID of Oracle database instance>"
inactivity-timeout="30"/>
</data-sources>
2). configuration repository update
OAS의 경우 configuration repositiory를 위해 다음과 같이 합니다.
prompt$ dcmctl shell -v
DCMCTL> updateConfig -ct oc4j -v
DCMCTL> getState -v
DCMCTL> stop -co < OC4J component name > -v
DCMCTL> start -co < OC4J component name > -v
DCMCTL> exit
3) source code
a. JNDI lookup
예를 들어, 다음과 같이 JNDI lookup을 통하여 OC4J connection pool을 사용하도록 변경하여 주시기 바랍니다.
...
import javax.naming.*;
import oracle.jdbc.pool.OracleDataSource;
InitialContext ic = null;
OracleDataSource ods = null;
Connection conn = null;
...
try {
ic = new InitialContext();
ods = (DataSource)ic.lookup("/jdbc/DataSource1");
} catch (NamingException e) {
e.printStackTrace();
%><%= e.getMessage() %><%
}
...
b. getting database connection
그 다음 database connection을 가져와 사용하고 close하는 부분은 기존의 code와 같을 것입니다.
...
try {
conn = ods.getConnection();
...
} catch (SQLException e) {
...
} finally {
try {
conn.close();
} catch (SQLException e) {
...
}
}