Statement

Statement objects are used to run SQL commands on the data grid. Queries (SELECT statements) and data manipulation language (DML) SQL commands can be run by using Statement objects. Statement objects are created by invoking the createStatement() method on the Session object.

A Statement object is created for each individual SQL command. A Statement can be run multiple times and must be closed when it is no longer needed.

You can either create a query using the SELECT statement or update rows using an INSERT or an INSERT OR REPLACE statement. The INSERT statement is supported for both, transacted and non-transacted sessions. For details on INSERT statement, see The SQL INSERT Statement. For information about INSERT OR REPLACE statement, see The INSERT OR REPLACE Statement.

Related concepts

Parameters

Parameters are used to separate the data of an SQL command from the command itself. This can be useful when the same command can be run multiple times by just varying the data of the command thereby increasing performance of the data grid. Parameters can be used to prevent SQL injection attacks in queries.

Parameters in an SQL command are specified using '?' (question mark). For SELECT statements, parameters are supported for the values of comparisons in WHERE clauses. For INSERT statements, parameters are supported for column values.

The Statement interface provides methods for setting the values of any parameters used in an SQL command. Separate methods for setting parameter values are provided for each data type supported by ActiveSpaces. The setNull() method is provided to specify that a parameter's value must be empty (SQL NULL). All parameter values must be specified prior to running the statement or an error is returned.

Running Statements

The Statement interface provides two methods for executing the statement. The executeQuery() method is used to run statements, which have been created using a SELECT command. The executeQuery() method returns a ResultSet object that contains the resulting rows of a query.

The executeUpdate() method is used to run statements which have been created using a DML command. The executeUpdate() method returns the number of rows that were successfully processed. If the wrong method is used to run a statement, an error is returned. For information about the current list of DML commands supported, see the TIBCO ActiveSpaces Release Notes.