# How Do I: Use a Database from a Web Service?

You can access a database from a web service by using a Database control. You can either use and existing Database control or create a new one.

To Add an Existing Database Control to Your Web Service

1. From the Insert menu, choose Control-->Database. The Insert Controls - Insert Database dialog appears.
2. In Step 1, enter the name you will use to refer to the new Database control. This name must be a valid Java identifier.
3. In Step 2 of the dialog, select the Use a Database control already defined by a JCX file radio button.
4. In the JCX file field, enter the name of the JCX file or click Browse to find the file in your project.
5. Click Create.

To Create a New Database Control for Your Web Service

1. If you are not in Design View, click the Design View tab.
2. From the Insert menu, choose Database. The Insert Control - Insert Database dialog appears.
3. In the Variable name for this control field, type the name for your database control.
4. Select the Create a new Database control to use with this service radio button.
5. In the New JCX name field, type the name of the new control file.
6. 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 Creating a New Database Control.

7. Click Create.

Once you have added the Database control to your web service, you may invoke methods on the control as you would with any other Java object.

Related Topics

Adding a Method to a Database Control

Database Control

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

Using WebLogic Built-In Controls