Using JDBC Data Sources with ADF Business Components
Written by Blaise Ribet, Oracle Corporation
This tip explains how to use JDBC data sources with an ADF Business Components JSP application deployed on Oracle Application Server 10g. JDBC data sources provide a standard method for creating JDBC connections. They offer some advantages over JDeveloper connection objects: connection information is not hard-coded in any of your application files, and can be modified after deployment. This is very useful if you want to use a test database for development and testing, and a production database after the application has been deployed.
This tip uses an example ADF Business Components/Struts/JSP application. The example application was built with the default web application template, has a Struts page flow diagram with a single data page, and a single JSP page that displays Departments and Employees from the hr common schema. The name of the business components application module is HrModule. The business components were built using a JDeveloper connection called hr_conn; when the instructions refer to the hr_conn connection, you should substitute the name of your own connection.
The tip follows the steps for deploying a business components application as a web module; a section near the end of the document describes how to work with data sources if you are deploying your application as an EJB session bean.
Find the data source location
JDeveloper automatically creates an OC4J data source for each database connection in your JDeveloper installation. To find the location of the datasource that has been created for the hr_conn connection:
Create a New Application Module Configuration
Next, create a new application module configuration that uses a data source instead of a JDeveloper connection (alternatively you could edit your existing application module configuration).
Modify the Client to use the new Configuration
Next, modify your application client to use the new configuration you have just created.
Create a New Application Server Connection
This section describes how to deploy your application to Oracle Application Server 10g, Oracle 9i Application Server or standalone OC4J.
Note: Before deploying your application to the application server, you may need to install the ADF runtime libraries. See the document Application Servers Supported by JDeveloper.
Create a Deployment Profile and Deploy Your Application
Finally, you modify the data source of your deployed application to connect to your production database. Note that your application server administrator or DBA can do this task without opening JDeveloper, and your developers do not need to be told the username and password of your production database.
Modify the Data Source on Oracle Application Server 10g or Oracle 9iAS
Follow these steps if you have deployed your application to Oracle Application Server 10g or Oracle 9iAS
Modify the Data Source on Standalone OC4J
If you have deployed your application to a standalone OC4J server you can modify a data source by editing the OC4J data sources file (data-sources.xml) directly.
Test your Application
When the OC4J server has restarted, you can test your application. A quick way to find the URL to access your deployed application is to run the local copy of your application in JDeveloper, and copy the target URL from JDeveloper's Embedded OC4J Server message window. Paste this URL into your browser, and replace the embedded OC4J hostname and port with your production application server's hostname and port.
If you are developing your application in JDeveloper 9.0.3 or 9.0.4, there are some differences in the steps you have to follow to work with data sources, mainly because earlier versions of JDeveloper do not have a dialog for editing data sources or property inspector support for editing the client data model (cpx) file. This section describes these differences, working with a BC4J JSP application.
Configuring your Application to Use a Data Source
Find the data source location
Create a new application module configuration
The steps for creating a new application module are the same in JDeveloper 9.0.3, 9.0.4 and 10g (9.0.5).
Modify the client to use the new configuration
Deploying your Application to the Application Server
Follow the usual steps, described in the online documentation, for deploying your application to Oracle Application Server or Standalone OC4J.
Modifying Data Sources on the Application Server
Follow the steps described earlier in this document.
When you create a deployment profile for deploying your business components as an EJB session bean, JDeveloper automatically creates a new business components configuration that uses the correct data source, you should use this configuration and not create a new configuration yourself. You do need to modify your client to use the new configuration, then follow the steps to deploy your business components as described in the JDeveloper online documentation