Oracle
  Home arrow Oracle arrow Page 3 - Deploying J2EE Applications
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ORACLE

Deploying J2EE Applications
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2007-03-15


    Table of Contents:
  • Deploying J2EE Applications
  • Types of Data Sources
  • Creating Data Sources
  • Managing Data Sources
  • Deploying Web Application Modules

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Deploying J2EE Applications - Creating Data Sources
    ( Page 3 of 5 )

    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:

      <data-source
     
       class= "com.evermind.sql.DriverManagerDataSource"
        name="OracleDS"
        location="jdbc/OracleCoreDS"
        xa-location="jdbc/xa/OracleXADS"
        ejb-location="jdbc/OracleDS" 
        connection-driver="oracle.jdbc.driver.OracleDriver"
        username="scott"
        password="tiger" 
        url= "jdbc:oracle:thin:@//localhost:1521/ORCL"
        inactivity-timeout="30"
      />

    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
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek