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/common/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.
Some early versions of Tomcat 4.0 when used with JDK 1.4 will not load classes12.zip unless you unzip the file, remove the javax.sql.*
class heirarchy and rejar.
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. server.xml configuration
In a similar manner to the mysql config above, you will need to define your Datasource in your server.xml file. 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"/>
<ResourceParams name="jdbc/myoracle">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@127.0.0.1:1521:mysid</value>
</parameter>
<parameter>
<name>username</name>
<value>scott</value>
</parameter>
<parameter>
<name>password</name>
<value>tiger</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
|
|
|
|
|
2. web.xml configuration
You should ensure that you respect the elemeent 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.
|
|
|
|
|
相关推荐
DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序中使用,Tomcat的数据源使用的就是DBCP; 使用连接池的第一项工作就是导包,这里需要的两个jar包分别是: commons-dbcp-1.4....
该例子中主要是通过dbcp连接数据库 详见: http://blog.csdn.net/renlei0109/article/details/32711943
DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种
DBCP(DataBase Connection Pool)是 apache common上的一个 java 连接池项目,也是 tomcat 使用的连接池组件,依赖 于Jakarta commons-pool 对象池机制,DBCP可以直接的在应用程序中使用。 使用DBCP会用到commons-...
DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要2个包:commons-dbcp.jar,commons-pool.jar由于建立数据库连接是一个非常耗时耗...
DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。 单独使用dbcp需要3个包:common-dbcp.jar,common-pool.jar,common-collections.jar 由于建立...
DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要2个包:commons-dbcp.jar,commons-pool.jar由于建立数据库连接是一个非常耗时耗...
DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要3个包:commons-dbcp.jar,commons-pool.jar,commons-collections.jar由于建立...
commons-dbcp-1.4-bin.zip commons-pool-1.5.6-bin.zip
commons-dbcp-1.2和commons-pool-1.3的jar包
DBCP(DataBase Connection Pool)是 apache common上的一个 java 连接池项目,也是 tomcat 使用的连接池组件,依赖 于Jakarta commons-pool 对象池机制,DBCP可以直接的在应用程序中使用。 使用DBCP会用到commons-...
配置tomcat数据源所需的常用jar包之一:commons-pool-1.5.4.jar DBCP数据源
commons-dbcp-1.4.jar,commons-pool-1.5.6.jar DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种
commons-pool-1.6,commons-dbcp-1.4 连接池下载
commons-dbcp,commons-pool,dpcp,pool,资源包下载。测试通过,绝对好用~~~
DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种
DBCP包 commons-dbcp-1.2.1.zip commons-pool-current.zip
DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种,由Apache开发,通过数据库连接池,可以让程序自动管理数据库连接的释放和断开 亲测可用,用于java DBCP的链接必须jar包
数据源和连接池的jar包 commons-dbcp-1.2.2.jar commons-pool-1.3.jar
DBCP(DataBase connection pool)数据库连接池。是 Apache 上的一个 Java 连接池项目,也是 tomcat 使用的连接池组件。单独使用DBCP需要2个包: * commons-dbcp.jar * commons-pool.jar。