Oracle ADF Faces Cookbook
上QQ阅读APP看书,第一时间看更新

Connecting your application to a database

In this application, we want to display employees' data from the HR schema on a web browser and be able to navigate between different records using buttons that help us go to the first, next, previous, and last records; employees' information should be displayed in a form-based view.

In order to retrieve employees' information, we need to establish a connection with the HR database.

In this recipe, we will use JDeveloper to establish a connection between our new ADF application and the HR schema, which comes by default with the Oracle database.

How to do it…

In order to establish a connection with the HR schema, follow the ensuing steps:

  1. Expand the Connect to a Database checklist item from the checklist and click on the Create a Database Connection button that will open the Create Database Connection dialog.

    Tip

    You can also create a connection by navigating to File | New | From Gallery | General | Connections | Database Connection.

  2. Choose a connection name of your choice; I named it HRConnection for clarification.
  3. Change the username and password of the HR user to match your database's HR schema; make sure you are pointing to the right host.
  4. Click on the Test Connection button to make sure everything works fine, and if everything is fine, you should see a Success! message.
    How to do it…
  5. Click on OK to close the dialog box.
  6. Mark this item as done in the checklist as well.

How it works…

When working with applications in ADF, you will need to have connections in order to establish a communication channel with different systems. One of the important connections that will be usually needed is a database connection, which establishes a connection between your application and database.

When you entered the information, you provided the connection with all the information needed in order to connect to a specific user in a specific database instance.

Your connection can be an application-based resource like the one we configured in this recipe; alternatively, it can be inside JDeveloper's resource catalog, which can be helpful if you have multiple applications that use the same database connection.

After creating a database connection, we need to create the Business Service Layer that will use the database connection.