Provides methods to execute a SQL query to generate a ResultSet object, or to execute a prepared SQL statement on a database.
public interface PreparedStatement
All members of PreparedStatement interface, including all inherited members.
Name | Description |
---|---|
Closes the PreparedStatement to release the memory resources associated with it. | |
Executes the prepared SQL statement. | |
Executes the prepared SQL SELECT statement and returns a ResultSet object. | |
Returns an OutputStream object. | |
Returns a Writer object. | |
Returns the (base-one) ordinal for the value represented by the name. | |
Returns a text-based description of the SQL query execution plan. | |
Returns a text-based description of the SQL query execution plan, represented as a tree. | |
Returns the ResultSet object for a prepared SQL statement. | |
Returns the number of rows inserted, updated or deleted since the last execute statement. | |
Determines if the PreparedStatement object contains a ResultSet object. | |
Sets a value to the host variable in the SQL statement. | |
Sets a null value to the host variable in the SQL statement. |
The following example demonstrates how to create a PreparedStatement object, check if a SELECT statement execution creates a ResultSet object, save any ResultSet object to a local variable, and then close the PreparedStatement:
// Create a new PreparedStatement object from an existing connection. String sql_string = "SELECT * FROM SampleTable"; PreparedStatement ps = conn.prepareStatement(sql_string); // Result returns true if the statement runs successfully. boolean result = ps.execute(); // Check if the PreparedStatement object contains a ResultSet object. if (ps.hasResultSet()) { // Store the ResultSet in the rs variable. ResultSet rs = ps.getResultSet; } // Close the PreparedStatement object to release resources. ps.close(); |
When a statement contains expressions, it may contain a host variable wherever a column name could appear. Host variables are entered as either a '?' characters (unnamed host variables) or as ":name" (named host variable).
In the following example, there are two host variables that may be set using the PreparedStatement object, and were prepared for the SQL statement in question:
SELECT * FROM SampleTable WHERE pk > :bound AND pk < ? |
close method
execute method
executeQuery method
getBlobOutputStream method
getClobWriter method
getOrdinal method
getPlan method
getPlanTree method
getResultSet method
getUpdateCount method
hasResultSet method
set method
setNull method
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |