Adding a Method to a JDBC control

The JDBC control provides access to a relational database. The methods that you add to the JDBC control execute SQL commands against the database. This topic discusses the mechanics of adding a method to a JDBC control.

Specifying the SQL Statement

A method on a JDBC control always has an associated SQL statement, which executes against the database when the method is called. The method's @JdbcControl.SQL annotation describes the method's SQL statement.

A sample method is provided in the comment header when you create a JDBC control:

@JdbcControl.SQL(statement="SELECT ID, NAME FROM CUSTOMERS WHERE ID = {id}") 
Customer findCustomer(int id) throws SQLException;

The method's SQL statement may include substitution parameters. These parameters are replaced at runtime with the values that were passed to the method. The names of the substitution parameters in the SQL statement must match those in the method signature, so that Workshop knows which parameter to replace with which value. Within the SQL statement, substitution parameters are enclosed in curly braces.

In the example above, the SQL statement includes the substitution{id}. This maps to the id parameter of the findCustomer method. When the method is invoked, the values of any referenced parameters are substituted in the SQL statement before it is executed. Note that parameter substitution is case sensitive, so parameters mentioned in substitutions must exactly match the spelling and case of the parameters to the method.

The method signature declares a method that a user of this control may invoke. You should design this method so that its arguments and return value are convenient and useful to developers of applications that will use this control.

The rules of parameter substitution in JDBC control method SQL statements are described in the JDBC control documetation .

The return type of the database operation is determined by the return type of the Java method. Workshop attempts to format the results in whatever type you have specified for the method to return.

A method of a JDBC control can return a single value, a single row, or multiple rows. To learn more about the values returned by JDBC control methods, see the JDBC control documentation .

Related Topics

Using System Controls

JDBC control

Creating a New JDBC control


Still need help? Post a question on the Workshop newsgroup.