[이클립스 팁] Eclipse에서 아파치 커넥션풀(ConnectionPool) 세팅하기 :: 소림사의 홍반장!

Oracle 8i, 9i & 10g

0. Introduction

Oracle requires minimal changes from the MySQL configuration except for the usual gotchas :-)

Drivers for older Oracle versions may be distributed as *.zip files rather than *.jar files. Tomcat will only use*.jar files installed in $CATALINA_HOME/lib. Therefore classes111.zip or classes12.zip will need to be renamed with a .jar extension. Since jarfiles are zipfiles, there is no need to unzip and jar these files - a simple rename will suffice.

For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.

1. Context configuration

In a similar manner to the mysql config above, you will need to define your Datasource in your Context. Here we define a Datasource called myoracle using the thin driver to connect as user scott, password tiger to the sid called mysid. (Note: with the thin driver this sid is not the same as the tnsname). The schema used will be the default schema for the user scott.

Use of the OCI driver should simply involve a changing thin to oci in the URL string.

<Resource name="jdbc/myoracle" auth="Container"
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
              username="scott" password="tiger" maxActive="20" maxIdle="10"
              maxWait="-1"/>

2. web.xml configuration

You should ensure that you respect the element ordering defined by the DTD when you create you applications web.xml file.

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

3. Code example

You can use the same example application as above (asuming you create the required DB instance, tables etc.) replacing the Datasource code with something like

Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
//etc.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

박스 안 내용 복사하기

 

이클립스에서 서버의 context.xml 열기

 

 

 

 

붙여넣고 자신의 환경에 맞게 수정하기

 

 

 

박스 안 내용 복사하기

 

 

사용할 프로젝트에 있는 web.xml 열기

 

 

 

 

붙여넣기 밑 리스너 설정하기

 

 

 

리스너에 해당하는 클래스 생성

 

 

 

박스 안 내용 복사하기

 

 

생성한 InitListener에 붙여넣고 추가 코딩하기

 

 

 

붙여넣기시 임포트 해야 되는 경로

 

 

 

붙여넣기시 임포트 해야 되는 경로

 

 

 

 

 

 

 

클래스 내에서 사용시 코딩 방법 ( getConnection하기 전에 DataSource에서 불러온다 )

 

다른 카테고리의 글 목록

Dev. 참고자료 카테고리의 포스트를 톺아봅니다