Java Reference
In-Depth Information
pstmt.executeUpdate();
}
}
Thisexamplefirstcreatesa String objectthatspecifiesanSQL INSERT statement.
Each“ ? ”characterservesasaplaceholderforavaluethat'sspecifiedbeforethestate-
ment is executed.
After the PreparedStatement implementation instance has been obtained, this
interface's void setInt(int parameterIndex, int x) and void
setString(int parameterIndex, String x) methods are called on
this instance to provide these values (the first argument passed to each method is
a 1-based integer column index into the table associated with the statement—1 cor-
responds to the leftmost column), and then PreparedStatement 's int ex-
ecuteUpdate() method is called to execute this SQL statement. The end result: a
pair of rows containing John Doe , Sally Smith , and their respective identifiers
are added to the EMPLOYEES table.
CallableStatement
CallableStatement isthemostspecializedofthestatementinterfaces;itextends
PreparedStatement . You use this interface to execute SQL stored procedures,
wherea stored procedure isalistofSQLstatementsthatperformaspecifictask(e.g.,
fire an employee). Java DB differs from other RDBMSes in that a stored procedure's
body is implemented as a public static Java method. Furthermore, the class in
which this method is declared must be public .
You create a stored procedure by executing an SQL statement that typically begins
with CREATE PROCEDURE andthencontinueswithRDBMS-specificsyntax.Forex-
ample,theJavaDBsyntaxforcreatingastoredprocedure,asspecifiedonthewebpage
at http://db.apache.org/derby/docs/dev/ref/rrefcreatepro-
cedurestatement.html , is as follows:
CREATE PROCEDURE procedure-name ([ procedure-parameter [,
procedure-parameter ] ]*)
[ procedure-element ]*
procedure-name is expressed as
[ schemaName .] SQL92Identifier
procedure-parameter is expressed as
[{ IN | OUT | INOUT }] [ parameter-Name ] DataType
Search WWH ::




Custom Search