Oracle - connection Pooling with spring framework

后端 未结 5 2018
萌比男神i
萌比男神i 2021-02-01 11:38

We are trying to implement Oracle connection pooling with the help of Spring Framework. We are using DBCP connection pooling method. However the integration between DBCP and spr

相关标签:
5条回答
  • 2021-02-01 11:52

    I was also facing the same problem as you are.. so i used Oracle Native connection pool.. it works smoothly..

    here is the link for the details http://www.lambdaprobe.org/d/oracle.shtml

    Thanks! Pratik

    0 讨论(0)
  • 2021-02-01 11:59

    I use C3PO to establish the connection. It has also the advantage to do connection pooling for you. Just define a datasource bean of type e.g. com.mchange.v2.c3p0.ComboPooledDataSource (or similar) through your spring config files. Before I run into troubles with connection pooling, I even used one of spring (DriverManagerDataSource) that is not advised for production use, because it is not actually doing the connection pooling.

    Here is an example spring configuration.

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:XE"/>
        <property name="user" value="username"/>
        <property name="password" value="secret"/>
        <property name="minPoolSize" value="5"/>
        <property name="maxPoolSize" value="20"/>
        <property name="acquireIncrement" value="1"/>
        <property name="idleConnectionTestPeriod" value="100"/>
        <property name="maxStatements" value="0"/>
        <property name="checkoutTimeout" value="60000"/>
    

    Spring then injects the dataSource bean into Hibernate and all is well. You will also need to have the c3pO jar file on your classpath...

    0 讨论(0)
  • 2021-02-01 12:00

    I would use Oracles supplied solution, which in included in their ojdbc jars. The older way was with the class OracleConnectionPoolDataSource but now you can set a parameter on a regular OracleDataSource and get connection pooling.

    Here is how to do it in Spring:

    <bean id="datasource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
       <property name="connectionCachingEnabled" value="true" />
       <property name="URL" value="${jdbc.url}" />
       ...all your connection properties
       <property name="connectionCacheProperties">
          <props merge="default">
             <prop key="MinLimit>3</prop>
             <prop key="MaxLimit">20</prop>
          </props>
       </property>
    </bean>
    
    0 讨论(0)
  • 2021-02-01 12:07

    You should not implementing your own pooling, if that's what you're using. Tomcat already does that for you, instead, define a data source in Tomcat, and have your ORM framework use it (when you define your Tomcat data source, you can specify the pool configurations there).

    If you could post some code snippets, specifically, the relevant Spring context configurations, I can help provide you with how you'd do this.

    Here's Tomcat documentation that shows you exactly how you do that:

    • http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

    Incidentally, Tomcat uses DBCP also, and it's better to rely on JNDI, as it makes your code more portable (from one environment to another - e.g., dev to staging to production, or even across application servers - e.g., to WebSphere, WebLogic etc).

    0 讨论(0)
  • 2021-02-01 12:08

    Instead of Using SimpleNativeJdbcExtractor use CommonsDbcpNativeJdbcExtractor to get the native connection. it works.

    When working with a simple connection pool that wraps Connections but not Statements, a SimpleNativeJdbcExtractor is often sufficient. However, some pools (like Jakarta's Commons DBCP) wrap all JDBC objects that they return: Therefore, you need to use a specific NativeJdbcExtractor (like CommonsDbcpNativeJdbcExtractor) with them.

    Click here [http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractor.html]

    0 讨论(0)
提交回复
热议问题