X

Learn Tips and Best Practices from the Oracle JDBC Development

  • May 21, 2015

UCP with Spring Framework





This article illustrates the steps to use Oracle Universal Connection Pool (UCP) with the Spring framework, using a sample application built using the JDBC template.


  • Assume there is a simple table EMP in the database with a single column “name” that is loaded with employee information (i.e., employee names).

  • Consider the following example DAO class in the package “test”:


  • The following is an example of the Row mapper implementation class for the EMP table:


  • The following class is the example of a java class that uses the JDBC Template for implementing the business logic:


  • The XML configuration file should specify UCP's oracle.ucp.jdbc.PoolDataSourceImpl as the data source class along with relevant connection pool properties, such as the initial-pool-size, max-pool-size, etc. For this sample, the XML configuration file is named "HelloAppConf.xml".
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!-- Initialization for data source -->
    <bean id="dataSource" class="oracle.ucp.jdbc.PoolDataSourceImpl">
    <property name="connectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
    <property name="URL" value="jdbc:oracle:thin:@//host:port/service_name"/>
    <property name="user" value="scott"/>
    <property name="password" value="tiger"/>
    <property name="maxPoolSize" value="10"/>
    <property name="initialPoolSize" value="5"/>
    </bean>
    <!-- Definition for EmpJDBCTemplate bean -->
    <bean id="EmpJDBCTemplate" class="test.EmpJDBCTemplate">
    <property name="dataSource" ref="dataSource"/>
    </bean>
    </beans>


  • The main application code looks like the following. The application using the JDBC template will internally use the Universal Connection Pool (UCP) for connection check-outs and check-ins.



Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.