18 June 2009

Weblogic Server DataSource Using TNS Names

As of Oracle JDBC 10.2, it's possible to establish a connection with the thin driver using tnsnames.

http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/urls.htm#BEIDIJCE

This allows you to store your database server details in an external tnsnames.ora file, which you then reference from the JDBC connection URL.

To use this with a Weblogic Server DataSource, try the following:

  1. Create a tnsnames.ora file with the required connection details and store it in a file that is accessible to the WLS instance:
    TEST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = testserver)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = test.au.oracle.com)
    )
    )

  2. Edit the setDomainEnv script for your domain and add the following System property
    -Doracle.net.tns_admin=<PATH_TO_TNS_NAMES_FILE>

  3. Create a DataSource and specify the connection URL to use the TNS names entry:
      <name>basic</name>
    <jdbc-driver-params>
    <url>jdbc:oracle:thin:@TEST</url>
    <driver-name>oracle.jdbc.xa.client.OracleXADataSource</driver-name>
    <properties>
    <property>
    <name>user</name>
    <value>banker</value>
    </property>
    </properties>
    <password-encrypted>{AES}fOJ/qlGxQjpdSiPODvxxilPHy/VuQe8yXggSSh1Lw4c=</password-encrypted>
    </jdbc-driver-params>

When the connection pool needs to create connections, it will lookup and use the specified TNS names entry from tnsnames.ora file in the directory specified oracle.net.tns_admin property.

2 comments:

martha said...

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Susan

http://8080proxy.com

icyjamie said...

We've tried this, but when we specify a target (server), we still get an error, saying you have to provide a host.

James