개발

Tomcat5.5 DBCP설정.

학생. 2007. 3. 8. 05:26
마음은 글도 좀 해석해서 요약하고싶은 맘이지만.
그림만 보고 따라했다.

0. Introduction

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

Drivers for older Oracle versions may be distributed as *.zip files ratherthan *.jar files. Tomcat will only use*.jarfiles installed in$CATALINA_HOME/common/lib. Thereforeclasses111.ziporclasses12.zipwill need to be renamed with a.jarextension. Since jarfiles are zipfiles, there is no need to unzip and jar thesefiles - a simple rename will suffice.

Some early versions of Tomcat 4.0 when used with JDK 1.4 will not loadclasses12.zip unless you unzip the file, remove thejavax.sql.*class heirarchy and rejar.

For Oracle 9i onwards you should useoracle.jdbc.OracleDriverrather thanoracle.jdbc.driver.OracleDriveras Oracle have statedthatoracle.jdbc.driver.OracleDriveris deprecated and supportfor this driver class will be discontinued in the next major release.

1. server.xml configuration

In a similar manner to the mysql config above, you will need to define yourDatasource in your server.xml file. Here we define a Datasource called myoracleusing the thin driver to connect as user scott, password tiger to the sidcalled mysid. (Note: with the thin driver this sid is not the same as thetnsname). 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 elemeent ordering defined by the DTD when youcreate 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 DBinstance, 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.
사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지

출처 :www.apache.org
반응형