java.sql.CallableStatement interface
Derby Reference Manual
311
Assume that we have a table TABLE1 defined as follows:
CREATE TABLE TABLE1 (C11 int, C12 int GENERATED ALWAYS AS IDENTITY)
The following three code fragments will all do the same thing: that is, they will create a
ResultSet that contains the value of
C12
that is inserted into TABLE1.
Code fragment 1:
Statement stmt = conn.createStatement();
stmt.execute(
"INSERT INTO TABLE1 (C11) VALUES (1)",
Statement.RETURN_GENERATED_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
Code fragment 2:
Statement stmt = conn.createStatement();
String [] colNames = new String [] { "C12" };
stmt.execute(
"INSERT INTO TABLE1 (C11) VALUES (1)",
colNames);
ResultSet rs = stmt.getGeneratedKeys();
Code fragment 3:
Statement stmt = conn.createStatement();
int [] colIndexes = new int [] { 2 };
stmt.execute(
"INSERT INTO TABLE1 (C11) VALUES (1)",
colIndexes);
ResultSet rs = stmt.getGeneratedKeys();
If there is no indication that auto-generated columns should be made available for
retrieval, a call to Statement.getGeneratedKeys will return a null ResultSet.
java.sql.CallableStatement interface
Derby supports all methods of CallableStatement except setBlob, getBlob, setClob, and
getClob.
CallableStatements and OUT Parameters
Derby supports OUT parameters and CALL statements that return values, as in the
following example:
CallableStatement cs = conn.prepareCall(
"? = CALL getDriverType(cast (? as INT))"
cs.registerOutParameter(1, Types.INTEGER);
cs.setInt(2, 35);
cs.executeUpdate();
Note: Using a CALL statement with a procedure that returns a value is only supported
with the ? = syntax.
Register the output type of the parameter before executing the call.
CallableStatements and INOUT parameters