Returning a Single Value from a Database Control Method
This topic discusses methods that you can add to Database control that return a single value from the database, including updates, inserts and single-valued select statements.
To learn about Database controls, see Database Control: Using a Database from Your Web Service.
To learn about creating a Database control, see Creating a New Database Control.
Examples of database operations that return a single value are INSERT and UPDATE operations, which return the number of rows affected; or SELECT statements that request only a single column of a single row. In these cases, the return value of the method should be an object or primitive of the appropriate type.
In the following example, an UPDATE operation is performed and the number of rows affected is returned:
/** * @jws:sql statement="UPDATE customer SET address={customerAddr} WHERE custid={customerID}" */ public intsetCustomerAddress(intcustomerID, String customerAddr);
This example updates the customer table. For each record in the table in which the custid field matches the value of the customerID parameter, the address field is set to the value of the customerAddr parameter.
In the following example a single column of a single row is returned (assuming custid is the primary key for the customer table). The field type is VARCHAR, so the return value is declared as String.
/** * @jws:sql statement="SELECT name FROM customer WHERE custid={customerID}" */ public String getCustomerName(intcustomerID);
To learn about the relationship between database types and Java types, see Mapping Database Field Types to Java Types in the Database Control.
Database Control: Using a Database from Your Web Service
Creating a New Database Control
Parameter Substitution in @jws:sql Statements