Top Description Methods
org.apache.derby.iapi.sql

public Interface PreparedStatement

extends Dependent
Known Direct Subinterfaces
org.apache.derby.iapi.sql.execute.ExecPreparedStatement
Imports
org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.depend.Dependent, .Provider, org.apache.derby.iapi.types.DataTypeDescriptor, java.sql.Timestamp, .SQLWarning

The PreparedStatement interface provides methods to execute prepared statements, store them, and get metadata about them.

Method Summary

Modifier and TypeMethod and Description
public ResultSet

Returns:

A ResultSet for a statement. A ResultSet represents the results returned from the statement, if any. Will return NULL if the plan for the PreparedStatement has aged out of cache, or the plan is out of date.
execute
(Activation
The activation containing all the local state to execute the plan.
activation
,
boolean
true if this is a meta-data query
forMetaData
,
long
timeout value in milliseconds.
timeoutMillis
)

Execute the PreparedStatement and return results, used for top level statements (not substatements) in a connection.

public ResultSet

Returns:

A ResultSet for a statement. A ResultSet represents the results returned from the statement, if any. Will return NULL if the plan for the PreparedStatement has aged out of cache, or the plan is out of date.
executeSubStatement
(Activation
The activation of the superstatement
parent
,
Activation
The activation containing all the local state to execute the plan for substatement
activation
,
boolean
True if in the event of a statement-level exception, the parent context needs to be rolled back, too.
rollbackParentContext
,
long
timeout value in milliseconds.
timeoutMillis
)

Execute a statement as part of another statement (ithout a nested connection) and return results.

public ResultSet

Returns:

a result set for the statement
executeSubStatement
(LanguageConnectionContext
language connection context
lcc
,
boolean
True if in the event of a statement-level exception, the parent context needs to be rolled back, too.
rollbackParentContext
,
long
timeout value in milliseconds.
timeoutMillis
)

Execute a statement as part of another statement (without a nested connection) and return results.

public Activation

Returns:

The new activation.
getActivation
(LanguageConnectionContext
The LanguageConnectionContext.
lcc
,
boolean
Scrollability
scrollable
)

PreparedStatements are re-entrant - that is, more than one execution can be active at a time for a single prepared statement.

public Timestamp

Returns:

Timestamp The timestamp for the beginning of compilation.
getBeginCompileTimestamp
()

Get the timestamp for the beginning of compilation

public long

Returns:

long The bind time for the associated query in milliseconds.
getBindTimeInMillis
()

Get the bind time for the associated query in milliseconds.

public long

Returns:

long The total compile time for the associated query in milliseconds.
getCompileTimeInMillis
()

Get the total compile time for the associated query in milliseconds.

public SQLWarning

Returns:

the warnings
getCompileTimeWarnings
()

Return any compile time warnings.

public Timestamp

Returns:

Timestamp The timestamp for the end of compilation.
getEndCompileTimestamp
()

Get the timestamp for the end of compilation

public long

Returns:

long The generate time for the associated query in milliseconds.
getGenerateTimeInMillis
()

Get the generate time for the associated query in milliseconds.

public long

Returns:

long The optimize time for the associated query in milliseconds.
getOptimizeTimeInMillis
()

Get the optimize time for the associated query in milliseconds.

public DataTypeDescriptor

Returns:

the parameter type
getParameterType
(int
The 0-based index of the parameter
idx
)

Get the type of the parameter at the given (0-based) index.

public DataTypeDescriptor[]

Returns:

An array of DataTypeDescriptors telling the type, length, precision, scale, etc. of each parameter of this PreparedStatement.
getParameterTypes
()

Get an array of DataTypeDescriptors describing the types of the parameters of this PreparedStatement.

public long

Returns:

long The parse time for the associated query in milliseconds.
getParseTimeInMillis
()

Get the parse time for the associated query in milliseconds.

public ResultDescription

Returns:

A ResultDescription describing the results.
getResultDescription
()

Get the ResultDescription for the statement.

public String

Returns:

the SQL string this statement is for.
getSource
()

Return the SQL string that this statement is for.

public String

Returns:

the SPS Name for this statement
getSPSName
()

Return the SPS Name for this statement.

public long

Returns:

version counter
getVersionCounter
()

Get the version counter.

public boolean

Returns:

boolean Whether or not this Statement is atomic
isAtomic
()

Returns whether or not this Statement requires should behave atomically -- i.e. whether a user is permitted to do a commit/rollback during the execution of this statement.

public boolean

Returns:

true if references SESSION schema tables, else false
referencesSessionSchema
()

Return true if the query node for this statement references SESSION schema tables.

public void
rePrepare(LanguageConnectionContext
The LanguageConnectionContext.
lcc
)

Re-prepare the statement if it is not up to date or, if requested, simply not optimal.

public boolean

Returns:

TRUE if the PreparedStatement is up to date, FALSE if it is not up to date
upToDate
()

Checks whether this PreparedStatement is up to date.

Inherited from org.apache.derby.iapi.sql.depend.Dependent:
isValidmakeInvalidprepareToInvalidate

Method Detail

executeback to summary
public ResultSet execute(Activation activation, boolean forMetaData, long timeoutMillis) throws StandardException

Execute the PreparedStatement and return results, used for top level statements (not substatements) in a connection.

There is no executeQuery() or executeUpdate(); a method is provided in ResultSet to tell whether to expect rows to be returned.

Parameters
activation:Activation

The activation containing all the local state to execute the plan.

forMetaData:boolean

true if this is a meta-data query

timeoutMillis:long

timeout value in milliseconds.

Returns:ResultSet

A ResultSet for a statement. A ResultSet represents the results returned from the statement, if any. Will return NULL if the plan for the PreparedStatement has aged out of cache, or the plan is out of date.

Exceptions
StandardException:
Thrown on failure
executeSubStatementback to summary
public ResultSet executeSubStatement(Activation parent, Activation activation, boolean rollbackParentContext, long timeoutMillis) throws StandardException

Execute a statement as part of another statement (ithout a nested connection) and return results.

There is no executeQuery() or executeUpdate(); a method is provided in ResultSet to tell whether to expect rows to be returned.

Parameters
parent:Activation

The activation of the superstatement

activation:Activation

The activation containing all the local state to execute the plan for substatement

rollbackParentContext:boolean

True if in the event of a statement-level exception, the parent context needs to be rolled back, too.

timeoutMillis:long

timeout value in milliseconds.

Returns:ResultSet

A ResultSet for a statement. A ResultSet represents the results returned from the statement, if any. Will return NULL if the plan for the PreparedStatement has aged out of cache, or the plan is out of date.

Exceptions
StandardException:
Thrown on failure
executeSubStatementback to summary
public ResultSet executeSubStatement(LanguageConnectionContext lcc, boolean rollbackParentContext, long timeoutMillis) throws StandardException

Execute a statement as part of another statement (without a nested connection) and return results.

Creates a new single use activation and executes it, but also passes rollbackParentContext parameter.

Parameters
lcc:LanguageConnectionContext

language connection context

rollbackParentContext:boolean

True if in the event of a statement-level exception, the parent context needs to be rolled back, too.

timeoutMillis:long

timeout value in milliseconds.

Returns:ResultSet

a result set for the statement

Exceptions
StandardException:
on error
See Also
executeSubStatement(Activation, Activation, boolean, long)
getActivationback to summary
public Activation getActivation(LanguageConnectionContext lcc, boolean scrollable) throws StandardException

PreparedStatements are re-entrant - that is, more than one execution can be active at a time for a single prepared statement. An Activation contains all the local state information to execute a prepared statement (as opposed to the constant information, such as literal values and code). Each Activation class contains the code specific to the prepared statement represented by an instance of this class (PreparedStatement).

Parameters
lcc:LanguageConnectionContext

The LanguageConnectionContext.

scrollable:boolean

Scrollability

Returns:Activation

The new activation.

Exceptions
StandardException:
Thrown on failure
getBeginCompileTimestampback to summary
public Timestamp getBeginCompileTimestamp()

Get the timestamp for the beginning of compilation

Returns:Timestamp

Timestamp The timestamp for the beginning of compilation.

getBindTimeInMillisback to summary
public long getBindTimeInMillis()

Get the bind time for the associated query in milliseconds.

Returns:long

long The bind time for the associated query in milliseconds.

getCompileTimeInMillisback to summary
public long getCompileTimeInMillis()

Get the total compile time for the associated query in milliseconds. Compile time can be divided into parse, bind, optimize and generate times.

Returns:long

long The total compile time for the associated query in milliseconds.

getCompileTimeWarningsback to summary
public SQLWarning getCompileTimeWarnings()

Return any compile time warnings. Null if no warnings exist.

Returns:SQLWarning

the warnings

getEndCompileTimestampback to summary
public Timestamp getEndCompileTimestamp()

Get the timestamp for the end of compilation

Returns:Timestamp

Timestamp The timestamp for the end of compilation.

getGenerateTimeInMillisback to summary
public long getGenerateTimeInMillis()

Get the generate time for the associated query in milliseconds.

Returns:long

long The generate time for the associated query in milliseconds.

getOptimizeTimeInMillisback to summary
public long getOptimizeTimeInMillis()

Get the optimize time for the associated query in milliseconds.

Returns:long

long The optimize time for the associated query in milliseconds.

getParameterTypeback to summary
public DataTypeDescriptor getParameterType(int idx) throws StandardException

Get the type of the parameter at the given (0-based) index. Raises an exception if the index is out of range.

Parameters
idx:int

The 0-based index of the parameter

Returns:DataTypeDescriptor

the parameter type

Exceptions
StandardException:
if the index is out of range
getParameterTypesback to summary
public DataTypeDescriptor[] getParameterTypes()

Get an array of DataTypeDescriptors describing the types of the parameters of this PreparedStatement. The Nth element of the array describes the Nth parameter.

Returns:DataTypeDescriptor[]

An array of DataTypeDescriptors telling the type, length, precision, scale, etc. of each parameter of this PreparedStatement.

getParseTimeInMillisback to summary
public long getParseTimeInMillis()

Get the parse time for the associated query in milliseconds.

Returns:long

long The parse time for the associated query in milliseconds.

getResultDescriptionback to summary
public ResultDescription getResultDescription()

Get the ResultDescription for the statement. The ResultDescription describes what the results look like: what are the rows and columns?

This is available here and on the ResultSet so that users can see the shape of the result before they execute.

Returns:ResultDescription

A ResultDescription describing the results.

getSourceback to summary
public String getSource()

Return the SQL string that this statement is for.

Returns:String

the SQL string this statement is for.

getSPSNameback to summary
public String getSPSName()

Return the SPS Name for this statement.

Returns:String

the SPS Name for this statement

getVersionCounterback to summary
public long getVersionCounter()

Get the version counter. A change in the value indicates a recompile has happened.

Returns:long

version counter

isAtomicback to summary
public boolean isAtomic()

Returns whether or not this Statement requires should behave atomically -- i.e. whether a user is permitted to do a commit/rollback during the execution of this statement.

Returns:boolean

boolean Whether or not this Statement is atomic

referencesSessionSchemaback to summary
public boolean referencesSessionSchema()

Return true if the query node for this statement references SESSION schema tables.

Returns:boolean

true if references SESSION schema tables, else false

rePrepareback to summary
public void rePrepare(LanguageConnectionContext lcc) throws StandardException

Re-prepare the statement if it is not up to date or, if requested, simply not optimal. If there are open cursors using this prepared statement, then we will not be able to recompile the statement.

Parameters
lcc:LanguageConnectionContext

The LanguageConnectionContext.

Exceptions
StandardException:
thrown if unable to perform
upToDateback to summary
public boolean upToDate() throws StandardException

Checks whether this PreparedStatement is up to date. A PreparedStatement can become out of date if any of several things happen: A schema used by the statement is dropped A table used by the statement is dropped A table used by the statement, or a column in such a table, is altered in one of several ways: a column is dropped, a privilege is dropped, a constraint is added or dropped, an index is dropped. A view used by the statement is dropped. In general, anything that happened since the plan was generated that might cause the plan to fail, or to generate incorrect results, will cause this method to return FALSE.

Returns:boolean

TRUE if the PreparedStatement is up to date, FALSE if it is not up to date

Exceptions
StandardException:
on error