Results 1 to 7 of 7

Thread: How do I set Oracle specific JDBC connection properties in bean def?

  1. #1
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    2

    Default How do I set Oracle specific JDBC connection properties in bean def?

    I am using DBCP and Oracle, and I need to set some Oracle specific properties on the conneciton. I have had no luck finding any documentation on this. BasicDataSource has a method called addConnectionProperty.


    Any help would be appreciated! Thanks!!
    Nathan

  2. #2

    Default

    Code:
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
    		<property name="url" ref="jdbc:oracle:thin:@host:port:env"/>
    		<property name="username"><value>xxx</value></property>
    		<property name="password"><value>xxx</value></property>
    	</bean>
    Trevor Ings

  3. #3
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    2

    Default

    Thanks for the reply. I already have my DBCP properteis set up, similar to the code you provided. (I was not able to post my code snippet)

    My datasource is working properly, I just need to know how to set a custom Oracle property. For example:

    in Java:
    Properties props = new Properties();
    props.set("oracle.jdbc.someproperty", "true");
    conn.setConnectionProperties(props);

    How can I do this in the bean definition?
    Thanks!

  4. #4
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    It's not pretty, but many of the jdbc drivers allow you to add properties on the connection url. Separated by question marks, ampersands or whatever. So check the Oracle driver's docs.

  5. #5

    Default

    Check documentation for org.springframework.jdbc.datasource.AbstractDriver BasedDataSource, it would imply that you can set custom properties on your datasource via

    Code:
    <property name="connectionProperties">
       <props>
           <prop key="com.oracle.xxxx" value="xxxx"/>
       </props>
    </property>
    Trevor Ings

  6. #6
    Join Date
    Oct 2009
    Posts
    1

    Default

    Hi Nathan,
    I have the same issue. Were you able to find out a solution???
    I tried in vain to use a solution like:
    <property name="connectionProperties">
    <props>
    <prop key="v$session.program" value="xxxx"/>
    </props>
    </property>
    Thanks.
    Maj

  7. #7
    Join Date
    Jul 2008
    Posts
    10

    Default

    I switched to c3p0 which allows you to add a hook when creating a connection.
    Code:
      <bean
          id="dataSource"
          class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="preferredTestQuery" value="${jdbc.validationQuery}"/>
        <property
            name="connectionCustomizerClassName"
            value="com.example.OracleConnectionCustomizer"/>
      </bean>
    The onAcquire method is called after each connection is created.
    Code:
    public class OracleConnectionCustomizer extends AbstractConnectionCustomizer {
        
        @Override
        public void onAcquire(
                Connection connection, String parentDataSourceIdentityToken)
            throws Exception
        {
            // Follow synonyms when retrieving metadata.
            ((OracleConnection) connection).setIncludeSynonyms(true);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •