Cross Column

Showing posts with label Database Connection. Show all posts
Showing posts with label Database Connection. Show all posts

Tuesday, May 24, 2011

Configuring JDBC Data Sources in JDeveloper and Oracle WebLogic Server

In a previous article, we have introduced different ways of creating and managing database connections in JDeveloper. Those connections (i.e. using JDBC URL) are good for the testing of JDeveloper Design-time, Business Components Tester, and Integrated WebLogic Server.

In the production environment, the web application would typically reference a JDBC datasource, since it simplifies maintenance of the connection credentials by allowing them to be centrally managed in the Java EE container. In this article, we will show you how to:
  • Switch from JDBC URL to JDBC DataSource in JDeveloper.
  • Setup global JDBC DataSource for database connection in the WebLogic Server
  • Deploy a Web Application to the WebLogic Server
JDBC URL vs. JDBC DataSource

If you use JDBC URL connection type, you provide settings as shown below:
However, if you use JDBC DataSource connection type, its settings are done on the server. To avoid passwords being present in plain text in deployed files, JDeveloper uses password indirection, which means that passwords for the data sources must be set on the server before the application will run correctly.

A data source object enables a Java Database Connectivity (JDBC) client to obtain a DBMS connection from a JDBC pool. A data source is a vendor-independent encapsulation of a database server connection. The data source offers advantages over a JDBC URL connection because the data source can be tuned, reconfigured, or remapped without changing the deployed application.

In WebLogic Server, you configure database connectivity by adding data sources to your WebLogic domain. WebLogic JDBC data sources provide database access and database connection management. Each data source contains a pool of database connections that are created when the data source is created and at server startup.

Choosing JDBC DataSource

After you finish testing your application using Integrated WebLogic Server and decide to deploy it to a standalone WebLogic Server, then it's time to configure JDBC DataSource as your application's connection type.

This configuration step is done on the Application Module in the Business Layer.
Edit Business Components Configuration dialog is used to create a new application module configuration or edit an existing one. To open it, do:

Application Navigator context menu for application modules > Configurations > Edit > Application Module tab

You choose to connect to a JDBC DataSource from the dropdown list. The JDeveloper helps create the data source name based on available resource connections. This data source naming convention follows the Java EE standard which specifies that resource connections appear in the application-specific name space java:comp/env/jdbc/. For example, for a connection named 'SmmApp', the JDBC Datasource name would be 'java:comp/env/jdbc/SmmAppDS'.

When you deploy the application and run it in standalone Oracle WebLogic Server, the specified data source connection in the application module configuration will be used.

Setting up Global JDBC DataSource

You can create a global data source on Oracle WebLogic Server Administration Console:

  • http://xbox.mycompany.com:7001/console/
To set up a global data source:
  1. Login to the Oracle WebLogic Server Administration Console. Click on the Data Sources link under JDBC. On the Summary of JDBC Data Sources page, click New. In the Create a New JDBC Data Source page, enter details of the data source.
  2. The name can be anything.
  3. The JNDI name must be of the form jdbc/connection-nameDS. For example, if the application has a connection name SmmApp, the JNDI name is jdbc/SmmAppDS. Ensure that the database type is Oracle and that the driver is Oracle’s Driver (Thin) for Service Connections;Version 9.0.1,9.2.0,10,11. Click Next twice to navigate to the Create a New JDBC Data Source page, where you enter the connection details.
  4. The database name is the Oracle SID.
  5. The host name is the the name of the machine the database is on.
  6. The default port is 1521.
  7. Enter the user name and password, for example hr/hr. Click Next and click Test Configuration. Click Next to navigate to the Select Targets page, where you select a target for this data source. If you fail to select a target, the data source is created but not deployed. Click Finish.

Steps to Deploy to WebLogic Server

Application Properties Dialog is used to to define the deployment profiles that will be available to an application. To open Deployment page, do:

Application menu > Application Properties > Deployment page

Makre sure "Auto Generate and Synchronize weblogic-jdbc.xml Descriptors During Deployment" is unchecked. When this field is not selected, this means that your deployed application will use global data sources on the server.
You can also edit the default deployment profile (i.e. SmmTest_application1--EAR File) or create a new one if needed.

There are two options for the deployment:
  1. Deployed to Ear
  2. Deployed to Application Server
If you want to deploy your application directly to the server, configure Resource Palette with a new Application Server Connection (i.e., xbox) as follows:
You then deploy your application using context menu. Right select your application and select Deploy. Choose the destination to be your application server (i.e., xbox).

References
  1. Database Connections in JDeveloper 11
  2. JDBC Datasources Work in the Business Components Browser in 11g
  3. Configuring JDBC Data Sources
  4. Configuring JDBC Data Sources (WebLogic)
  5. What You May Need to Know About JDBC DataSource
  6. Oracle WebLogic Server Downloads 
  7. Oracle® Fusion Middleware Configuring and Managing JDBC Data Sources for Oracle WebLogic Server 11g Release 1 (10.3.6)

Monday, March 15, 2010

Database Connections in JDeveloper 11

JDeveloper 11 Technology introduces a new way to create and manage database connections. Now Database connections can be defined in two ways:
  1. For an application--You can create a database connection owned by and deployed with the current application, which is listed in Application Resource
  2. For the IDE as a whole--You can also create a connection that can be added to any application (i.e., IDE Connections), which is listed in both Resource Palette and Database Navigator.

Before you can use an IDE connection, you need to add it to your application as shown in the figure:

Creating Database Connections

If the data sources of your business components are from database, you need to create database connections to access them in your applications. Creating database connection can be either initiated by the user or triggered by other events such as creating the first business component in your application or importing an ADF library JAR which includes a connection.

In this article, we'll look at these different scenarios.

Creating the First Business Component

When you create the first business component, say, use the following steps:
  • New > Business Tier > ADF Business Components > Business Components from Tables
JDeveloper will prompt you with an "Initialize Business Components Project" dialog because it detects that your selected project has not yet been initialized for Business Components. In this initialization step, you need to specify the database connection as shown here:

Importing an ADF Library JAR with Connections

If the project you are packaging into an ADF Library JAR includes a database connection, that information can be included in the JAR and may be available to the consuming project. Oracle ADF uses connection architecture which defines a connection as two parts:
  1. Connection name
  2. Connection details (or endpoint definition).
JDeveloper will present the producer of the JAR the option to package the connection name only or to include connection details with the connection name.

If a connection is present in the project, the packaged ADF Library JAR will contain a jar-connections.xml file and a jar-adf-config.xml file. They will be added to the META-INF directory. The jar-connections.xml file contains the connection name and other relevant connection information. The jar-adf-config.xml file stores the information about the credentials used for the connections. If connection credentials were also specified, then a jar-credential-jazn-data.xml will also be included for the credential store.

If the connection defined in the JAR is fully configured and there are no connection name conflicts with the consuming project, a new application connection will be added.

If you don't create extra business components after importing the packaged ADF Library JAR, you don't need to go through Initialize Project for Business Components step as described below. Just make sure your database connection settings are correct by opening it in Application Resources panel.

Initialize Project for Business Components


If you choose, you can create database connections in advance and initialize your project for business components using them.

As described before, IDE connections are located in either Resource Palette or Database Navigator. You can create new database connections from context menu as shown below:


After creating your IDE connections, you then add them to your application. Besides IDE connections, you can also create database connections for your application only. All database connections used by your application will be listed in Application Resources panel.

Besides creating database connections from context menu, you can also create database connections (in either IDE or application scope) from New Gallery using the following steps:
  • New > General > Connections > Database Connection

After creating database connections in your application, the next step is to initialize your project for business components. Selecting model project from your application, open its property from the context menu.
Selecting Business Component tab, check "Initialize Project for Business Components" and then select the database connection to be used for creating business components. Note that this connection is used specifically for:
  • JDeveloper Design-time and
  • Business Components Tester

and it is different from the one used at runtime when your web application is deployed to an Application Server. That's another topic for the next time.

Read More...

  1. Database connection in ADF BC 11g
  2. Oracle Fusion Middleware Online Documentation Library 11g Release (11.1.1.2)
  3. Database Connections in JDeveloper 11
  4. Oracle JDeveloper

© Travel for Life Guide. All Rights Reserved.

Analytical Insights on Health, Culture, and Security.