How to create a DataSource in JBoss application se

2019-02-15 00:07发布

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

Thanks in Advance

标签: java xml jboss
2条回答
smile是对你的礼貌
2楼-- · 2019-02-15 00:39

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

查看更多
我只想做你的唯一
3楼-- · 2019-02-15 00:43

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();
查看更多
登录 后发表回答