PreparedStatement Example

From InterBase
Jump to: navigation, search

Go Up to Executing Stored Procedures


In the example below, the multiply stored procedure is not selectable. Therefore, you have to call the procedure with the PreparedStatement class. The procedure arguments are the scale factor and the value of KEYCOL that uniquely identifies the row to be multiplied in the NUMBERS table.

//Define a PreparedStatement object type
java.sql.PreparedStatement preparedStatement;
//Create a new string object
java.sql.String sql = new String ("EXECUTE PROCEDURE multiply 10, 1");
//Create the PreparedStatement object
preparedStatement = connection.prepareStatement(sql);
//execute the stored procedure with preparedStatement
java.sql.ResultSet resultSet = preparedStatement.executeQuery(sql);
//step through the result set and print out as in Statement example