Installing Upgrading Designing Configuring Deploying Monitoring Administering Troubleshooting Reference JBI Components
Close Print View
Designing: Add Prepared Statement
 

Classic Java CAPS

Developing Java CAPS Projects

Using SOAP Message Handlers

Creating a Runtime Environment

Designing Business Processes in the Sun Business Process Manager

Working with TCP/IP HL7 Collaborations

Developing Sun Master Indexes (Repository)

Developing Sun Master Patient Indexes

Developing OTDs for Application Adapters

Developing OTDs for Communication Adapters

Developing OTDs for Database Adapters

Creating a New DB2 OTD

Select Wizard Type

Connecting to a Database

Selecting Database Objects

Selecting Table/Views/Aliases

Selecting Procedures

Add Prepared Statements

Specifying the OTD Name

To Specify the OTD Name

Reviewing Selections

Editing Existing OTDs

To Edit an Existing OTD

Creating a DB2 Connect OTD

Select Wizard Type

Connecting to Database

Selecting Database Objects

Selecting Table/Views/Aliases

Selecting Procedures

Adding Prepared Statements

Specifying the OTD Name

Review Selections

Editing Existing OTDs

To Edit an Existing OTD

Creating a New Informix OTD

Select Wizard Type

Connect To Database

Select Database Objects

Select Tables/Views/Aliases

Select Procedures

Add Prepared Statements

Specify the OTD Name

Review Selections

Steps to Edit an Existing Informix OTD

Steps to Edit the OTD from the Java CAPS IDE Include:

Creating a New JDBC OTD

Select Wizard Type

To Connect To Database

Select Database Objects

Select Tables/Views/Aliases

Select Procedures

Add Prepared Statement

Specify the OTD Name

Review Selections

Editing an Existing JDBC OTD

To Edit the OTD from the Java CAPS IDE

Creating an Oracle OTD

Select Wizard Type

Connect To Database

Select Database Objects

Select Tables/Views/Aliases

Select Procedures

Add Prepared Statement

Specify the OTD Name

Review Selections

Creating a New SQL Server OTD

Select Wizard Type

Connect to Database

Select Database Objects

Select Table/Views/Aliases

Select Procedures

Add Prepared Statements

Specify the OTD Name

Review Selections

Editing Existing OTDs

To Edit an Existing OTD

Creating a New Sybase OTD

Select Wizard Type

To Connect to Database

Select Database Objects

Select Tables/Views/Aliases

Select Procedures

Add Prepared Statement

Specify the OTD Name

Review Selections

Editing an Existing Sybase OTD

To Edit the OTD from the Java CAPS IDE

Creating a VSAM OTD

Select Wizard Type

Connect To Database

Select Database Objects

Select Tables/Views/Aliases

Add Prepared Statement

Specify the OTD Name

Review Selections

Using the OTD Importer in Netbeans

Developing OTDs for Web Server Adapters

Designing with Application Adapters

Designing with Communication Adapters

Designing with Web Server Adapters

SWIFT Integration Projects

Java EE Based Components

Designing with Sun JCA Adapters

About the TCP/IP JCA Adapter

Defining Constants and Variables

Using Database Operations

Developing Sun Master Indexes

Using the JMS JCA Wizard

Using the JAXB Wizard and Code-Seeder Pallete

Add Prepared Statement

A Prepared Statement OTD represents a SQL statement that has been compiled. Fields in the OTD correspond to the input values that users need to provide. Prepared statements can be used to perform insert, update, delete and query operations. A prepared statement uses a question mark (?) as a place holder for input. For example: insert into EMP_TAB (Age, Name, Dept No) values (?, ?, ?)

To execute a prepared statement, set the input parameters and call executeUpdate() and specify the input values if any.

To Add Prepared Statements

Note - When using a Prepared Statement, the ResultsAvailable() method will always return true. Although this method is available, you should not use it with a while loop. Doing so would result in an infinite loop at runtime and will stop all of the system’s CPU. If it is used, it should only be used with the if statement.You can process a resultset by looping through the next() method.

  1. In the Add Prepared Statements dialog box, click Add.
    Figure 27 Prepared Statement
    Prepared Statement
  2. Enter the name of a Prepared Statement and create a SQL statement by clicking in the SQL Statement dialog box or by clicking the Statement Builder button. When you are finished creating the statement, click Save As, which gives the statement the name you just entered. This name appears as a node in the OTD (see the figure below). Click OK.
    Figure 28 Prepared SQL Statement
    Prepared SQL Statement
  3. In the Add Prepared Statement dialog box, the name you assigned to the Prepared Statement appears. To edit the parameters, click Edit Parameters. You can change the datatype by clicking in the Type field and selecting a different type from the list.
  4. Click Add if you want to add additional parameters to the Statement, or highlight a row and click Remove to remove the parameter (see the following figure). Click OK.

    Note - Once you save the Prepared Statement, make sure that the ResultSet Column Name, in the Prepared Statement parameters, is a valid alpha-numeric string with no special characters (e.g. no brackets).

    Figure 29 Edit the Prepared Statement Parameters
    Edit the Prepared Statement Parameters
  5. To edit the ResultSet Columns, click Edit ResultSet Columns (see the figure below). Although both the Name and Type are editable, Sun recommends that you do not change the Name because it can cause a loss of integrity between the ResultSet and the Database. Click OK.

    Note - The OTD Wizard fails to create OTDs with complex prepared statements that use the same column name in different tables. This problem is resolved by modifying the SQL statement to use column name aliases.

    Figure 30 ResultSet Columns
    ResultSet Columns
  6. In the Add Prepared Statements dialog box, click OK.