Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

20 Configuring Data Sources

This chapter describes:

For more information, see:


Note:

You can download a data source code example from http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html.

Configuring a Data Source for an Oracle Database

To create a data source for an Oracle database, you create a managed datasource. You can create a managed data source using the Application Server Control Console (see "Using Application Server Control Console") or deployment XML (see "Using Deployment XML").

For more information, see:

Using Application Server Control Console

You can use Application Server Control Console to create a managed data source dynamically without restarting OC4J.

For more information, see http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html.

Using Deployment XML

You can configure a managed data source for an Oracle database by configuring a connection-pool element and managed-data-source element in the data-sources.xml file as Example 20-1 shows.

Example 20-1 data-sources.xml For an Oracle JDBC Data Source

<connection-pool name="ScottConnectionPool">
    <connection-factory
        factory-class="oracle.jdbc.pool.OracleDataSource"
        user="scott"
        password="tiger"
        url="jdbc:oracle:thin:@//localhost:1521/ORCL" >
    </connection-factory>
</connection-pool>
 
<managed-data-source
    name="OracleManagedDS"
    jndi-name="jdbc/OracleDS"
    connection-pool-name="ScottConnectionPool"
    tx-level="global"
/>

Be sure to specify a service-based connection URL in the connection-factory element (see "How Do You Define a Connection URL in OC4J?").

By default, a managed data source supports global (two-phase commit) transactions. To configure a managed data source to support only local transactions, set the managed-data-source attribute tx-level to local. For more information, see "What Transaction Types Do Data Sources Support?").

For more information, see:

If you configure a managed data source using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to create a data source dynamically without restarting OC4J (see Using Application Server Control Console)

Configuring a Data Source for a Third-Party Database

To create a data source for a third-party (non-Oracle) database, you create a native datasource. You can create a native data source using the Application Server Control Console (see "Using Application Server Control Console") or deployment XML (see "Using Deployment XML").

For more information, see:

Using Application Server Control Console

You can use Application Server Control Console to create a native data source dynamically without restarting OC4J.

For more information, see http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html.

Using Deployment XML

Example 20-2 shows how to define a native data source element for a third-party database (in this example, SQLServer).

Example 20-2 data-sources.xml for a Third-Party Database

<native-data-source
  name="nativeDataSource"
  jndi-name="jdbc/nativeDS"
  description="Native DataSource"
  data-source-class="com.ddtek.jdbcx.sqlserver.SQLServerDataSource"
  user="frank"
  password="frankpw"
  url="jdbc:datadirect:sqlserver://server_name:1433;User=usr;Password=pwd">
</native-data-source>

By default, a native data source supports only local transactions. For global (two-phase commit) transactions, configure a managed data source. For more information, see "What Transaction Types Do Data Sources Support?").

For more information, see:

If you configure a native data source using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to create a native data source dynamically without restarting OC4J (see "Using Application Server Control Console")

Configuring a Default Data Source for an EJB 3.0 Application

You can configure a default data source for an EJB 3.0 application using deployment XML (see "Using Deployment XML").

For more information, see:

Using Deployment XML

To configure a default data source for an EJB 3.0 application:

  1. Set the name of the default data source in the default-data-source attribute of your orion-application.xml file.

  2. Customize your EJB 3.0 application to define a data source of this name in your ejb3-toplink-session.xml file.

    For more information, see:

Configuring a Default Data Source for an EJB 2.1 Application

You can configure a default data source for an EJB 2.1 application using deployment XML (see "Using Deployment XML").

For more information, see:

Using Deployment XML

To configure a default data source for an EJB 2.1 application:

  1. Set the name of the default data source in the default-data-source attribute of the orion-application element in your orion-application.xml file.

  2. Set the name of the default data source in the data-source attribute of the entity-deployment element in your orion-ejb-jar.xml file.

  3. Define the default data source in the <OC4J_HOME>/j2ee/home/config/data-sources.xml file.