Home arrow Oracle arrow Page 3 - Deploying J2EE Applications

Creating Data Sources - Oracle

In this week's part of a multi-part series covering OC4J and J2EE applications, you will learn how to deploy J2EE applications, create data sources, and more. This article is excerpted from chapter eight of the Oracle 10g Application Server Exam Guide, written by Sam Alapati (McGraw-Hill; ISBN: 0072262710).

  1. Deploying J2EE Applications
  2. Types of Data Sources
  3. Creating Data Sources
  4. Managing Data Sources
  5. Deploying Web Application Modules
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 5
March 15, 2007

print this article



I’ll briefly describe how you can create data sources using the Application Server Control. Here are the steps:

  1. Go to the OC4J home page, click the Administration tab, and then click Data Sources.
  2. In the Application Data Sources page, click the Create button (you can also click the Create Like button if you want to pattern a new data source after an existing one).
  3. There are several sections in the Data Source Properties page (actually titled Create Data Source), which appear next. In the General section, fill in the name and description of the data source as well as the following information: 

    • Data source class
    • JDBC URL
    • JDBC driver
    • Schema

On the Job:  Your default data-sources.xml file provides predefined data sources that may suit your needs.

  1. In the Data Source Username and Password section, specify the username and password using the schema you chose in the previous section.
  2. In the JNDI Locations section, you specify the JNDI location string that is used for JNDI tree lookups when the application is retrieving the data source. Of the three attributes—Location, Transactional (XA) Location, and EJB Location—you are required to specify only the Location attribute. If you plan on having the EJBs use the database for Container Managed Persistence (CMP), you must specify the XA and EJB Location attributes. For a non-emulated data source, you must specify all three JNDI location attributes, although only the ejb-location is actually used.
  3. In the Connection Attributes section, you specify various connection-related attributes, such as the following:

    • Connection retry interval

    • Maximum connection attempts
    • Inactivity timeout period
    • Maximum and minimum number of open connections

  4. In the Properties section, you can specify properties for any custom or third-party data source you may be configuring.
  5. Once you have made the necessary configuration, click the Create button to create your new data source.

A DataSource object is used by developers to provide a logical representation of a database. It’s the job of the deployer to map this logical representation to a physical database. Using the logical DataSource object to look up the JNDI, the J2EE applications will retrieve the database names so they can connect to them. The deployer first uses the J2EE application file (EAR file), to locate the DataSource references in the deployment descriptor. The deployer will then create mappings between the database schemas matching the DataSource requirements, so the application can connect to it.

You must use an emulated data source for a single-phase commit, and you can utilize the default data source (data-sources.xml) for this purpose. Here’s the default data-sources.xml file:

   class= "com.evermind.sql.DriverManagerDataSource"
    url= "jdbc:oracle:thin:@//localhost:1521/ORCL"

Plug in your database URL information instead of the default URL shown in the data-sources.xml file. You must do this for each of the databases that are part of the transaction. The data source retrieval, as mentioned earlier, is done through a JNDI lookup. The JNDI name is shown by the ejb-location attribute.

Retrieving the Data Source Connection   Your first task before using the database for queries is to retrieve a connection to the database. To retrieve the database connection, you can perform a lookup on the JNDI name bound to the data source definition. Note that you may also perform a JNDI lookup by looking up the logical name that you defined in the environment of the bean container. You retrieve the database connection using the getConnection method. Using the data source definition, for example, you retrieve a database connection as follows:

  Context ic = new InitialContext();
  DataSource ds = (DataSource) ic.lookup("jdbc/OracleDS");
  Connection conn = ds.getConnection();

Because the data source already contains the username and password attributes, you can use the getConnection method without the username/password attributes.

>>> More Oracle Articles          >>> More By McGraw-Hill/Osborne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Oracle Java Security Woes Continue
- Oracle's New IaaS Cloud Option: There's a Ca...
- Oracle Acquires Eloqua to Boost Cloud Presen...
- Choosing Innovation: Oracle Survey Insights
- Oracle Fixes Privilege Escalation Bug
- Oracle`s Communications Service Availability...
- Oracle Releases Exalytics, Taleo Plans
- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator

Developer Shed Affiliates


Dev Shed Tutorial Topics: