Can anybody provide the steps for creating DataSource in JBoss server(5.0) with Oracle Database..
Thanks in Advance
Can anybody provide the steps for creating DataSource in JBoss server(5.0) with Oracle Database..
Thanks in Advance
This example assumes you're using Oracle 10i.
In JBoss 5, create an XML file ending with -ds.xml
(although not necessarily -ds
, it has to be an XML file). with the following descriptor elements.
This is an example to do Local-TX datasource.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources
PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
"http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
<datasources>
<local-tx-datasource>
<jndi-name>MyDataSourceName</jndi-name>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
<user-name>myUserName</user-name>
<password>myPassword</password>
<min-pool-size>20</min-pool-size>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
You can have more than 1 <local-tx-datasource>
element but <jndi-name>
must be unique.
For XA datasource, see an example here.
The above example is saved in MyDataSourceName-ds.xml
.
The XML file must be placed under JBOSS_HOME/server/<default|all>/deploy
folder.
Now, in Java, you will retrieve MyDataSourceName
as follows:
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:MyDataSourceName");
Connection connection = ds.getConnection();
Here is a link to JBoss that explains it for you.