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

You can access a database from a web service by using a Database control.

To Add an Existing Database Control to Your Web Service

  1. In Design View, from the Add Control drop-down list, select Add Database Control. The Add Database Control 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, click Use a Database control already defined by a CTRL file, then enter the name of the CTRL file or click  Browse to find the file in your project.

  4. Click Create.

To Create a New Database Control for Your Web Service

  1. In Design View, from the Add Control drop-down list, select Add Database Control. The Add Database Control 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, click Create a new Database control to use with this service.

  4. In the New CTRL name field, type a name for the CTRL file that you wish to create. This name will be used as the name for the Java interface that defines the Database control, so it must be a valid Java identifier.

  5. In step 3 of the dialog, in the Data source field, type the name for the data source you wish to use for this Database control or click Browse to select from a list of available JDBC data sources. The cgSampleDataSource data source is intended for experimentation.

  6. 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

Database Control: Using a Database from Your Web Service

Controls: Using Resources from a Web Service

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