3

Can anybody provide the steps for creating DataSource in JBoss server(5.0) with Oracle Database..

Thanks in Advance

Nithin
  • 255
  • 1
  • 6
  • 15

2 Answers2

9

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();
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • Buhake, thanks for the answer. What does "In JBoss 5.0" mean? Is it inside a specific folder? If JBoss is installed under c:\jboss-6.0, where should this XML file be placed? – wavicle Aug 15 '14 at 20:10
  • Each version of JBoss had major changes to XSD's and configurations. JBoss 7 is a total rewrite from JBoss 6. JBoss 6 should be the same with JBoss 5 in terms of directory but I know the datasource XSD was newer than JBoss 5's. – Buhake Sindi Aug 15 '14 at 23:57
  • @BuhakeSindi I want to encrypt connection-url and read in java to decrypt the same. How can we achieve that in Jboss5? – Dev G Apr 14 '17 at 01:39
2

Here is a link to JBoss that explains it for you.

Community
  • 1
  • 1
Marthin
  • 6,413
  • 15
  • 58
  • 95