<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JBoss.com - Wiki - SetUpAOracleDatasource</title>
<base href="http://www.jboss.com/"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="expires" content="0"/>
<meta name="keywords" content="jboss, jboss application server, application server."/>
<meta name="description" content="The Professional Open Source Company"/>
<meta name="ROBOTS" content="INDEX,FOLLOW"/>
<meta name="resource-type" content="document"/>
<meta name="author" content="The Professional Open Source Company"/>
<meta name="copyright" content="Copyright (c) 2004 by JBoss.com"/>
<meta name="revisit-after" content="1 days"/>
<meta name="distribution" content="Global"/>
<meta name="generator" content="Nukes on JBoss - http://www.jboss.org"/>
<meta name="rating" content="General"/>
<link rel="shortcut icon" href="/favicon.ico"/>
<link rel="stylesheet" href="themes/jbosstheme/style/custom.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/global.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/headings.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/navigation.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/pagelayout.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/tables.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/screen.css" type="text/css" media="screen">
<link rel="stylesheet" href="themes/jbosstheme/style/print.css" type="text/css" media="print">
<link rel="stylesheet" href="themes/jbosstheme/style/common.css" type="text/css" media="all">
<link rel="stylesheet" href="themes/jbosstheme/style/layout_new_branding.css" type="text/css" media="all">
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="themes/jbosstheme/style/iehacks.css" />
<![endif]-->
<script type="text/javascript" src="scripts/menu.js"></script>
<script language="JavaScript" src="themes/jbosstheme/js/functions.js" type="text/javascript"></script>
<script language="JavaScript" src="/elqNow/elqCfg.js" type="text/javascript"></script>
<script language="JavaScript" src="/elqNow/elqImg.js" type="text/javascript"></script></head><body>
<div class="brand_JEMS" id="container">
<div id="TopLogo">
<a href="http://www.jboss.com"><img src="themes/jbosstheme/img/logo.gif" alt="JBoss - The Professional Open Source Company" border="0" /></a>
</div>
<div id="TopMenu">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="menu_JBnetwork"><a href="http://network.jboss.com/">subscription</a></td>
<td class="menu_JBcom"><a href="http://www.jboss.com/">jboss.com</a></td>
<td class="menu_JBorg"><a href="http://labs.jboss.com">jboss.org</a></td>
<td class="menu_RH"><a href="http://www.redhat.com">redhat.com</a></td>
</tr>
</table>
</div>
<div id="ControlMenu">
<form id="TopSearch" action="search.jsp">
<ul>
<li><a href="http://www.jboss.com/fr/index"><img src="/images/languages/french.gif" border="0"></a></li>
<li><a href="http://de.jboss.com"><img src="http://www.jboss.com/images/languages/german.gif" border="0"></a></li>
<li><a href="http://www.jboss.com/index"><img src="/images/languages/english.gif" border="0"></a></li>
<li><a href="/index.html?op=loginscreen&module=user">Login</a></li>
<li><a href="/index.html?op=checkage&module=user">Register</a></li>
<li><a href="http://www.redhat.com/about/careers/">Careers</a></li>
<li><a href="/company/contact">Contact Us</a></li>
<li>
<input style="border: 1px solid #6e6e6e; font: 10px Verdana, Helvetica, Arial, sans-serif; padding-left: 2px; margin-left: 10px;" name="query" onfocus="SearchFocus(this)" onblur="SearchBlur(this)" value="Search..." />
<input class="searchbutton" type="image" src="themes/jbosstheme/img/spacer.gif" value="go" align="middle" />
</li>
</ul>
</form>
</div>
<div id="Breadcrumb">
<ul>
<li class="root"><a href="">Home</a></li>
<li><a href="">JBoss Enterprise Middleware System (JEMS)</a></li>
</ul>
</div>
<table cellpadding="0" cellspacing="0" id="BodyTable">
<tr>
<td colspan="2" class="topheader"></td>
</tr>
<tr>
<td class="leftside">
<div id="LeftMenu">
<ul>
<li class="current">
<a href="/products/index">JBoss Middleware</a>
<ul>
<li><a href="/products/platforms/application">Application Platform</a></li>
<li><a href="/products/platforms/portals">Portal Platform</a></li>
<li><a href="/products/platforms/dataservices">Data Services Platform</a></li>
<li><a href="/products/platforms/soa">SOA Platform</a></li>
<li><a href="/products/jbosson">Operations Network</a></li>
<li><a href="/products/devstudio">Developer Studio</a></li>
<li><a href="/products/hibernate">Hibernate Framework</a></li>
<li><a href="/products/jbpm">jBPM Framework</a></li>
<li><a href="/products/rules">Rules Framework</a></li>
<li><a href="/products/seam">Seam Framework</a></li>
<a> </a>
<li><a href="/downloads/index">Download</a></li>
<li><a href="/docs/index">Documentation</a></li>
<li><a href="/services/online_education">Online Education</a></li>
</ul>
</li>
<li><a href="http://www.jboss.org">JBoss.org Community</a></li>
<li><a href="/services/index">Support Services</a></li>
<li><a href="/partners/index">Partners</a></li>
<li><a href="/company/index">About Us</a></li>
<li><a href="http://www.jboss.com/jbossBlog/blog/" target="_blank">Blogs</a></li>
<li><a href="/opensource/index">Resource Centers</a></li>
<li><a href="http://store.jboss.com" target="_blank">JBoss Store</a></li>
</ul>
</div><!-- ### JEMS Ads - START -->
<div id="LeftAds">
<div class="item"><a href="/services/certification"><img src="/images/banners/jb_cert_ani_banner.gif" width="175" height="64" border="0"></a></div>
</div>
<!-- ### JEMS Ads - START -->
<div id="WhosOnline">
<table width="175" border="0" cellspacing="0" cellpadding="0">
<tr><td bgcolor="#eeeeee"> </td></tr>
<tr><td bgcolor="#eeeeee" style="font-size:10px; padding-left:5px;"> <b>Online:</b>
29167 guests, <a href="index.html?module=user&op=whosonline">52 members</a></td></tr>
<tr><td bgcolor="#eeeeee"> </td></tr>
<tr><td bgcolor="#eeeeee" style="font-size:10px; padding-left:5px;"> <b>Monthly JBoss newsletter:</b>
<form action="http://now.eloqua.com/f.asp" method=post style="padding:0pt;margin:0pt;">
<input type="hidden" name="elqFormName" value="emailform">
<input type="hidden" name="elqSiteID" value="257">
<input type="hidden" name="elqDefaultTargetURL" value="">
<input type="hidden" name="elqPost" value="">
<input name=email type=text style="margin-left:5px; margin-top:2px; border: 1px solid rgb(110, 110, 110); width: 120px; font-size: 10px;" onfocus="this.className=focus;if (this.value == my@email.address) this.value = ';" onblur="this.className=';if (this.value == ') this.value = my@email.address;" value="my@email.address"/>
<input style="vertical-align:middle;" type="image" name="submit" border="0" src="/images/btn_go_grey.gif">
</form>
</td></tr>
<tr><td bgcolor="#eeeeee"> </td></tr>
<tr><td><img vspace="1" src="images/side_nav_btm.gif" width="175" height="13"/></td></tr>
</table>
</div>
</td><td class="bodycell">
<div id="ContentContainer">
<table border="0" cellspacing="8" width="95%" bgcolor="#FFFFFF">
<tr>
<td class="page" width="85%" valign="top">
<p>
<table class="wikitable" border="1">
<tr><td><a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=Main">Home</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=About">About</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=FindPage">Search</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=RecentChanges">Changes</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=UnusedPages">Unused Pages</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=UndefinedPages">Undefined Pages</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=PageIndex">Index</a> </td><td> <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=DocumentationLicense">License</a></td></tr>
</table>
</p>
<p><hr /></p>
<p>
<a href="http://wiki.jboss.org/wiki/Edit.jsp?page=SetUpAOracleDatasource">Edit this page</a>
</p>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="left">
<h1 class="pagename"><a name="Top">SetUpAOracleDatasource</a></h1>
</td>
<td align="right">
<div class="searchbox">
<!-- SiteSearch Google -->
<!--
<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<TABLE bgcolor="#FFFFFF"><tr><td>
<td>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
<font size=-1>
<input type=hidden name=domains value="wiki.jboss.org"><br><input type=radio name=sitesearch value=""> WWW <input type=radio name=sitesearch value="wiki.jboss.org" checked> wiki.jboss.org <br>
</font>
</td></tr></TABLE>
</FORM>
-->
<!-- SiteSearch Google -->
</div>
</td>
</tr>
<tr>
<td colspan="2" class="breadcrumbs">Your trail: </td>
</tr>
</table>
<hr />
<b>beware of the file name</b>, save them in the server instance's deploy directory, eg. $JBOSS_HOME/server/default/deploy/oracle-ds.xml.
Note that only ONE local-tx datasource can be safely enlisted in a Transaction at a time. XA drivers are known to be viable for
Oracle 10g Drivers and above. They may work for Oracle 8 and 9 Drivers. Please test before using XA for Oracle 8 & 9 Drivers.
(There has been some success using Oracle 10g JDBC drivers against an Oracle 8 database).
<p>
<h4> XA</h4></p>
<p>
<pre>
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: oracle-xa-ds.xml,v 1.13 2004/09/15 14:37:40 loubyansky Exp $ -->
<!-- ===================================================================== -->
<!-- ATTENTION: DO NOT FORGET TO SET Pad=true IN transaction-service.xml -->
<!-- ===================================================================== -->
<datasources>
<xa-datasource>
<jndi-name>XAOracleDS</jndi-name>
<track-connection-by-tx/>
<isSameRM-override-value>false</isSameRM-override-value>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:oracle:oci8:@tc</xa-datasource-property>
<xa-datasource-property name="User">scott</xa-datasource-property>
<xa-datasource-property name="Password">tiger</xa-datasource-property>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
<no-tx-separate-pools/>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</xa-datasource>
<mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
name="jboss.jca:service=OracleXAExceptionFormatter">
<depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
</mbean>
</datasources>
</pre>
</p><p>
<h4> Local-TX</h4>
</p><p>
<pre>
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: oracle-ds.xml,v 1.6 2004/09/15 14:37:40 loubyansky Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Oracle originally from Steven Coy -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@youroraclehost:1521:yoursid</connection-url>
<!--
See on WIKI page below how to use Oracle's thin JDBC driver to connect with enterprise RAC.
-->
<!--
Here are a couple of the possible OCI configurations.
For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm
<connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
or
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
Clearly, its better to have TNS set up properly.
-->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>x</user-name>
<password>y</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
</pre>
</p><p>
<h3> Configuring a <a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=DataSources">DataSource</a> using Oracle's thin JDBC driver to connect with enterprise RAC</h3>
The magic is in the long connection-url. The two hostnames provide a load balancing and failover layer to the underlying physical database:
</p><p>
<pre>
...
<connection-url>jdbc:oracle:thin:@(description=(address_list=(load_balance=on)(failover=on)(address=(protocol=tcp)(host=xxxxhost1)(port=1521))(address=(protocol=tcp)(host=xxxxhost2)(port=1521)))(connect_data=(service_name=xxxxsid)(failover_mode=(type=select)(method=basic))))</connection-url>
...
</pre>
</p><p>
<i>Note: Example only confirmed against Oracle 10g.</i>
</p><p>
<h3> Changes in Oracle 10g JDBC driver</h3>
Preliminary testing seems to suggest that it is no longer necessary to enable the Pad option in your jboss-service.xml file. Further, the need for the <no-tx-seperate-pool/>
configuration appears to have also been removed. Note, to date, testing has been limited and only against the latest version of Oracle with the latest JDBC drivers.
</p><p>
<br />
<h3> How to retrieve the underlying Oracle connection object?</h3>
</p><p>
<pre>
Connection conn = myJBossDatasource.getConnection();
WrappedConnection wrappedConn = (WrappedConnection)conn;
Connection underlyingConn = wrappedConn.getUnderlyingConnection();
OracleConnection oracleConn = (OracleConnection)underlyingConn;
</pre>
</p><p>
<b>Referenced by:</b><br />
<a class="wikipage" href="http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigDataSources">ConfigDataSources</a><br />
</p>
<br clear="all" />
<p><hr />
<table border="0" width="100%">
<tr>
<td align="left">
<a href="#Top">Go to top</a>
<a href="http://wiki.jboss.org/wiki/Edit.jsp?page=SetUpAOracleDatasource">Edit this page</a>
<a class="pageinfo" href="http://wiki.jboss.org/wiki/PageInfo.jsp?page=SetUpAOracleDatasource">More info...</a>
<a href="javascript:window.open('http://wiki.jboss.org/wiki/Upload.jsp?page=SetUpAOracleDatasource','Upload','width=640,height=480,toolbar=1,menubar=1,scrollbars=1,resizable=1,').focus()">Attach file...</a>
<br />
</td>
</tr>
<tr>
<td align="left">
<font size="-1">
<i>This page last changed on <a href="http://wiki.jboss.org/wiki/Diff.jsp?page=SetUpAOracleDatasource&r1=16&r2=15">05-Dec-2006 05:41:13 EST</a> by luc.texier@jboss.com.</i>
</font>
</td>
</tr>
</table>
</p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<div id="footer">
<div class="leftcurve"></div>
<div>
<a href="http://www.redhat.com"><img src="jbosstheme/img/logo_rh_home.png" alt=" Red Hat" width="96" height="31" border="0" /></a><br />
<br />
<br />
</div>
<span style="text-align:center">
© 2007 Red Hat Middleware, LLC. All rights reserved.
<a href="http://www.jboss.com/privacy_policy">Privacy Policy</a>
</span>
</div>
</div>
<!-- SiteCatalyst code version: H.1.
Copyright 1997-2005 Omniture, Inc. More info available at
http://www.omniture.com sec -->
<div id="oTags">
<script type="text/javascript" src="/scripts/s_code.js"></script>
<script><!--
/* You may give each page an identifying name, server, and channel on
the next lines. */
s.pageName=""
s.server=""
s.channel=""
s.pageType=""
s.prop1=""
/* E-commerce Variables */
s.campaign=""
s.eVar1=""
s.eVar2=""
s.eVar3=""
s.events=""
s.products=""
s.state=""
s.zip=""
s.purchaseID=""
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script type="text/javascript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script><noscript><img
src="https://smtrcs.redhat.com/b/ss/redhatjboss/1/H.2--NS/0"
height="1" width="1" border="0" alt="" /></noscript><!--/DO NOT REMOVE/-->
</div>
<!-- End SiteCatalyst code version: H.1. -->
</body>
</html>