Creating a New Database Control

A Database control makes it easy to access a relational database via SQL commands. When you create a new Database control, you specify which database it connects to and write methods to access data using SQL commands. This topic describes the mechanics of creating a Database control.

Adding a Database Control

You can add a Database control in any of the following types of files:

To add a new Database control, follow these steps:
  1. Open the file to which you want to add the control in the WebLogic Workshop design environment.
  2. Display the Data Palette (View->Windows->Data Palette).
  3. On the Data Palette, click the Add drop-down, and choose Database. The Insert Control - Insert Database dialog opens.
  4. In the Variable name for this control field, type the name for your database control.
  5. Select the Create a new Database control to use with this service radio button.
  6. In the New JCX name field, type the name of the new control file.

    Note: In previous releases, JCX files were known as CTRL files. CTRL files are still supported.

  7. Decide whether you want to make this a control factory and select or clear the Make this a control factory that can create multiple instances at runtime check box. For more information about control factories, see Control Factories: Managing Collections of Controls.
  8. In the Step 3 pane, click Browse to select a data source. The JNDI Entries dialog appears. Navigate to the data source you want to select and click Select.

    Note: The cgSampleDataSource data source is available for experimentation. For more information about data sources, see the Choosing a Data Source section, below.

  9. Click Create.

You can also create a Database control file manually by copying an existing Database control file and modifying the copy.

To learn how to add a method to a Database control, see Adding a Method to a Database Control.

Choosing a Data Source

Before you can perform operations on a database, you must have a connection to the database. The Database control handles all of the details of managing the database connection, but you must supply the name of a data source that has been configured with the information necessary to access a database.

A default data source called cgSampleDataSource is configured when WebLogic Workshop is installed. This data source uses the PointBase database.

To learn how to create, configure and register a data source, see Configuring a Data Source and How Do I: Connect a Database Control to a Database Such as SQL Server or Oracle.

Once the data source is configured and registered in the JNDI registry, the data source name may be used in the data-source-jndi-name attribute of the @jc:connection annotation.

For detailed information on the @jc:connection annotation, see @jc:connection Annotation.

Note: If you are creating a Database control that connects to an Informix database, you must use a transactional (XA) driver to connect to the Informix database. For more information on transactional drivers for Informix, see the Informix documentation.

Related Topics

Built-In Controls Overview

Database Control

How Do I: Connect a Database Control to a Database Such as SQL Server or Oracle

Adding a Method to a Database Control

CustomerDBClient.jws Sample

LuckyNumberDBClient.jws Sample

DatabaseControl Interface

@jc:sql Annotation

@jc:connection Annotation