Package io.github.connellite.jdbc
Class NamedCallableStatement
java.lang.Object
io.github.connellite.jdbc.NamedCallableStatement
- All Implemented Interfaces:
AutoCloseable
CallableStatement wrapper with named parameters (e.g.
:id inside {call ...}).
Internally converts the call text to positional placeholders (?) and binds by index,
so drivers that reject CallableStatement named-parameter methods still work.
A function return is named too: {:ret = call func(:id)} becomes {? = call func(?)}.-
Constructor Summary
ConstructorsConstructorDescriptionNamedCallableStatement(Connection connection, String sql) Creates a named call and compiles it to JDBC positional placeholders.NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency) Creates a named call with a target result-set type and concurrency.NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a named call with result-set type, concurrency and holdability.NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, SqlParser sqlParser) Creates a named call with a custom parser, result-set type, concurrency and holdability.NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, SqlParser sqlParser) Creates a named call with a custom parser, target result-set type and concurrency.NamedCallableStatement(Connection connection, String sql, SqlParser sqlParser) Creates a named call using a custom SQL parser. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()Adds the current parameter set to a batch.voidClears wrapper binding state, OUT registration bookkeeping, and underlying JDBC parameter values.voidclose()booleanexecute()Executes the call after every named parameter has been set, registered, or both.int[]Executes the JDBC batch on the underlying call.Executes the call and returns the first result set, skipping update counts the same way asQueryUtils.selectFromCall(Connection, String, Object...).Reads an OUT or INOUTArray.getBigDecimal(String name) Reads an OUT or INOUTBigDecimal.Reads an OUT or INOUTBlob.booleangetBoolean(String name) Reads an OUT or INOUT boolean.Names of parameters bound withsetsince the lastclearParameters().byteReads an OUT or INOUT byte.byte[]Reads an OUT or INOUT byte array.getCharacterStream(String name) Reads an OUT or INOUT character stream.Reads an OUT or INOUTClob.Reads an OUT or INOUTDate.Reads an OUT or INOUTDatewith calendar.doubleReads an OUT or INOUT double.floatReads an OUT or INOUT float.intReads an OUT or INOUT int.longReads an OUT or INOUT long.booleanMoves to the next result of the underlying call.getNCharacterStream(String name) Reads an OUT or INOUT national character stream.Reads an OUT or INOUTNClob.getNString(String name) Reads an OUT or INOUT national string.Reads an OUT or INOUT object.<T> TReads an OUT or INOUT value converted totype.Reads an OUT or INOUT object using a SQL-to-Java type map.Returns parameter names in positional order (including repeated occurrences).Returns parsed call text transformed to JDBC placeholders.Reads an OUT or INOUTRef.Returns the current result set of the underlying call.Reads an OUT or INOUTRowId.shortReads an OUT or INOUT short.Reads an OUT or INOUTSQLXML.Reads an OUT or INOUT value.Reads an OUT or INOUTTime.Reads an OUT or INOUTTimewith calendar.getTimestamp(String name) Reads an OUT or INOUTTimestamp.getTimestamp(String name, Calendar cal) Reads an OUT or INOUTTimestampwith calendar.intReturns the current update count of the underlying call.Reads an OUT or INOUTURL.static NamedCallableStatementof(Connection connection, String sql) Static factory forNamedCallableStatement.static NamedCallableStatementof(Connection connection, String sql, int resultSetType, int resultSetConcurrency) Static factory forNamedCallableStatementwith result-set type and concurrency.static NamedCallableStatementof(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Static factory forNamedCallableStatementwith result-set type, concurrency and holdability.static NamedCallableStatementof(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, SqlParser sqlParser) Static factory forNamedCallableStatementwith result-set type, concurrency, holdability and a custom SQL parser.static NamedCallableStatementof(Connection connection, String sql, int resultSetType, int resultSetConcurrency, SqlParser sqlParser) Static factory forNamedCallableStatementwith result-set type, concurrency and a custom SQL parser.static NamedCallableStatementof(Connection connection, String sql, SqlParser sqlParser) Static factory forNamedCallableStatementwith a custom SQL parser.registerOutParameter(String name, int sqlType) Registers every occurrence ofnameas an OUT parameter.registerOutParameter(String name, int sqlType, int scale) Registers every occurrence ofnameas an OUT parameter with scale.registerOutParameter(String name, int sqlType, String typeName) Registers every occurrence ofnameas an OUT parameter with a database-specific type name.registerOutParameter(String name, SQLType sqlType) Registers every occurrence ofnameas an OUT parameter of the givenSQLType.registerOutParameter(String name, SQLType sqlType, int scale) Registers every occurrence ofnameas an OUT parameter of the givenSQLTypeand scale.registerOutParameter(String name, SQLType sqlType, String typeName) Registers every occurrence ofnameas an OUT parameter of the givenSQLTypeand type name.Binds all entries from map usingsetObject(String, Object).Binds SQL array value.setAsciiStream(String name, InputStream value) Binds ASCII stream.setAsciiStream(String name, InputStream value, int length) Binds ASCII stream with int length.setAsciiStream(String name, InputStream value, long length) Binds ASCII stream with long length.Binds@Bindmembers ofbean.setBigDecimal(String name, BigDecimal value) BindsBigDecimalvalue to all occurrences of named parameter.setBinaryStream(String name, InputStream value) Binds binary stream.setBinaryStream(String name, InputStream value, int length) Binds binary stream with int length.setBinaryStream(String name, InputStream value, long length) Binds binary stream with long length.setBlob(String name, InputStream inputStream) Binds blob binary stream value.setBlob(String name, InputStream inputStream, long length) Binds blob binary stream value with explicit length.BindsBlobvalue.setBoolean(String name, boolean value) Binds boolean value to all occurrences of named parameter.Binds byte value to all occurrences of named parameter.Binds byte array value to all occurrences of named parameter.setCharacterStream(String name, Reader reader) Binds character stream.setCharacterStream(String name, Reader reader, int length) Binds character stream with int length.setCharacterStream(String name, Reader reader, long length) Binds character stream with long length.Binds character reader as CLOB.Binds character reader as CLOB with explicit length.BindsClobvalue.BindsDatevalue to all occurrences of named parameter.BindsDatevalue with calendar to all occurrences of named parameter.Binds double value to all occurrences of named parameter.Binds float value to all occurrences of named parameter.Binds int value to all occurrences of named parameter.Binds long value to all occurrences of named parameter.setNCharacterStream(String name, Reader value) Binds NCHAR character stream.setNCharacterStream(String name, Reader value, long length) Binds NCHAR character stream with explicit length.Binds reader as NCLOB.Binds reader as NCLOB with explicit length.BindsNClobvalue.setNString(String name, String value) Binds national character string value.Binds SQL NULL of generic typeTypes.NULL.Binds SQL NULL with explicit JDBC type.Binds SQL NULL with explicit JDBC type and database-specific type name.Binds object value to all occurrences of named parameter.Binds object with explicit JDBC SQL type.Binds object with explicit JDBC SQL type and scale/length.Binds object withSQLType.Binds object withSQLTypeand scale/length.Binds SQL reference value.Binds JDBC row id value.Binds short value to all occurrences of named parameter.Binds SQLXML value.Binds string value to all occurrences of named parameter.BindsTimevalue to all occurrences of named parameter.BindsTimevalue with calendar to all occurrences of named parameter.setTimestamp(String name, Timestamp value) BindsTimestampvalue to all occurrences of named parameter.setTimestamp(String name, Timestamp value, Calendar cal) BindsTimestampvalue with calendar to all occurrences of named parameter.Binds URL value.unwrap()Returns the underlying JDBC callable statement.booleanwasNull()Reports whether the last value read by agetmethod was SQL NULL.
-
Constructor Details
-
NamedCallableStatement
Creates a named call and compiles it to JDBC positional placeholders.- Parameters:
connection- JDBC connection used to prepare the callsql- call text with named parameters (for example{call proc(:id)})- Throws:
SQLException
-
NamedCallableStatement
public NamedCallableStatement(Connection connection, String sql, SqlParser sqlParser) throws SQLException Creates a named call using a custom SQL parser.- Throws:
SQLException
-
NamedCallableStatement
public NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException Creates a named call with a target result-set type and concurrency.- Throws:
SQLException
-
NamedCallableStatement
public NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, SqlParser sqlParser) throws SQLException Creates a named call with a custom parser, target result-set type and concurrency.- Throws:
SQLException
-
NamedCallableStatement
public NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Creates a named call with result-set type, concurrency and holdability.- Throws:
SQLException
-
NamedCallableStatement
public NamedCallableStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, SqlParser sqlParser) throws SQLException Creates a named call with a custom parser, result-set type, concurrency and holdability.- Throws:
SQLException
-
-
Method Details
-
of
Static factory forNamedCallableStatement.- Throws:
SQLException
-
of
public static NamedCallableStatement of(Connection connection, String sql, SqlParser sqlParser) throws SQLException Static factory forNamedCallableStatementwith a custom SQL parser.- Throws:
SQLException
-
of
public static NamedCallableStatement of(Connection connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException Static factory forNamedCallableStatementwith result-set type and concurrency.- Throws:
SQLException
-
of
public static NamedCallableStatement of(Connection connection, String sql, int resultSetType, int resultSetConcurrency, SqlParser sqlParser) throws SQLException Static factory forNamedCallableStatementwith result-set type, concurrency and a custom SQL parser.- Throws:
SQLException
-
of
public static NamedCallableStatement of(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Static factory forNamedCallableStatementwith result-set type, concurrency and holdability.- Throws:
SQLException
-
of
public static NamedCallableStatement of(Connection connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, SqlParser sqlParser) throws SQLException Static factory forNamedCallableStatementwith result-set type, concurrency, holdability and a custom SQL parser.- Throws:
SQLException
-
setObject
Binds object value to all occurrences of named parameter.- Throws:
SQLException
-
setInt
Binds int value to all occurrences of named parameter.- Throws:
SQLException
-
setLong
Binds long value to all occurrences of named parameter.- Throws:
SQLException
-
setString
Binds string value to all occurrences of named parameter.- Throws:
SQLException
-
setBoolean
Binds boolean value to all occurrences of named parameter.- Throws:
SQLException
-
setByte
Binds byte value to all occurrences of named parameter.- Throws:
SQLException
-
setShort
Binds short value to all occurrences of named parameter.- Throws:
SQLException
-
setFloat
Binds float value to all occurrences of named parameter.- Throws:
SQLException
-
setDouble
Binds double value to all occurrences of named parameter.- Throws:
SQLException
-
setBigDecimal
BindsBigDecimalvalue to all occurrences of named parameter.- Throws:
SQLException
-
setBytes
Binds byte array value to all occurrences of named parameter.- Throws:
SQLException
-
setDate
BindsDatevalue to all occurrences of named parameter.- Throws:
SQLException
-
setDate
BindsDatevalue with calendar to all occurrences of named parameter.- Throws:
SQLException
-
setTime
BindsTimevalue to all occurrences of named parameter.- Throws:
SQLException
-
setTime
BindsTimevalue with calendar to all occurrences of named parameter.- Throws:
SQLException
-
setTimestamp
BindsTimestampvalue to all occurrences of named parameter.- Throws:
SQLException
-
setTimestamp
public NamedCallableStatement setTimestamp(String name, Timestamp value, Calendar cal) throws SQLException BindsTimestampvalue with calendar to all occurrences of named parameter.- Throws:
SQLException
-
setNull
Binds SQL NULL of generic typeTypes.NULL.- Throws:
SQLException
-
setNull
Binds SQL NULL with explicit JDBC type.- Throws:
SQLException
-
setNull
public NamedCallableStatement setNull(String name, int sqlType, String typeName) throws SQLException Binds SQL NULL with explicit JDBC type and database-specific type name.- Throws:
SQLException
-
setObject
public NamedCallableStatement setObject(String name, Object value, int targetSqlType) throws SQLException Binds object with explicit JDBC SQL type.- Throws:
SQLException
-
setObject
public NamedCallableStatement setObject(String name, Object value, int targetSqlType, int scaleOrLength) throws SQLException Binds object with explicit JDBC SQL type and scale/length.- Throws:
SQLException
-
setObject
public NamedCallableStatement setObject(String name, Object value, SQLType targetSqlType) throws SQLException Binds object withSQLType.- Throws:
SQLException
-
setObject
public NamedCallableStatement setObject(String name, Object value, SQLType targetSqlType, int scaleOrLength) throws SQLException Binds object withSQLTypeand scale/length.- Throws:
SQLException
-
setArray
Binds SQL array value.- Throws:
SQLException
-
setRef
Binds SQL reference value.- Throws:
SQLException
-
setURL
Binds URL value.- Throws:
SQLException
-
setRowId
Binds JDBC row id value.- Throws:
SQLException
-
setSQLXML
Binds SQLXML value.- Throws:
SQLException
-
setBlob
BindsBlobvalue.- Throws:
SQLException
-
setBlob
Binds blob binary stream value.- Throws:
SQLException
-
setBlob
public NamedCallableStatement setBlob(String name, InputStream inputStream, long length) throws SQLException Binds blob binary stream value with explicit length.- Throws:
SQLException
-
setClob
BindsClobvalue.- Throws:
SQLException
-
setClob
Binds character reader as CLOB.- Throws:
SQLException
-
setClob
Binds character reader as CLOB with explicit length.- Throws:
SQLException
-
setNClob
BindsNClobvalue.- Throws:
SQLException
-
setNClob
Binds reader as NCLOB.- Throws:
SQLException
-
setNClob
Binds reader as NCLOB with explicit length.- Throws:
SQLException
-
setAsciiStream
Binds ASCII stream.- Throws:
SQLException
-
setAsciiStream
public NamedCallableStatement setAsciiStream(String name, InputStream value, int length) throws SQLException Binds ASCII stream with int length.- Throws:
SQLException
-
setAsciiStream
public NamedCallableStatement setAsciiStream(String name, InputStream value, long length) throws SQLException Binds ASCII stream with long length.- Throws:
SQLException
-
setBinaryStream
Binds binary stream.- Throws:
SQLException
-
setBinaryStream
public NamedCallableStatement setBinaryStream(String name, InputStream value, int length) throws SQLException Binds binary stream with int length.- Throws:
SQLException
-
setBinaryStream
public NamedCallableStatement setBinaryStream(String name, InputStream value, long length) throws SQLException Binds binary stream with long length.- Throws:
SQLException
-
setCharacterStream
Binds character stream.- Throws:
SQLException
-
setCharacterStream
public NamedCallableStatement setCharacterStream(String name, Reader reader, int length) throws SQLException Binds character stream with int length.- Throws:
SQLException
-
setCharacterStream
public NamedCallableStatement setCharacterStream(String name, Reader reader, long length) throws SQLException Binds character stream with long length.- Throws:
SQLException
-
setNCharacterStream
Binds NCHAR character stream.- Throws:
SQLException
-
setNCharacterStream
public NamedCallableStatement setNCharacterStream(String name, Reader value, long length) throws SQLException Binds NCHAR character stream with explicit length.- Throws:
SQLException
-
setNString
Binds national character string value.- Throws:
SQLException
-
setAll
Binds all entries from map usingsetObject(String, Object).- Throws:
SQLException
-
setBean
Binds@Bindmembers ofbean.Each member is read by reflection. When
Bind.converter()is notTypeConverter.DefaultConverter,TypeConverter.convert(Object)runs first. Anullresult is bound withsetNull(String); any other result usessetObject(String, Object). Members whose names are not parameters of this statement are ignored. Collection values are not expanded.- Throws:
SQLException- when a converter cannot be created orconvertfailsIllegalArgumentException- whenbeanhas no@Bindmembers or none of those names are parameters of this statementIllegalStateException- when a member cannot be readNullPointerException- whenbeanisnull
-
registerOutParameter
Registers every occurrence ofnameas an OUT parameter. An INOUT parameter is both registered and set.- Throws:
SQLException
-
registerOutParameter
public NamedCallableStatement registerOutParameter(String name, int sqlType, int scale) throws SQLException Registers every occurrence ofnameas an OUT parameter with scale.- Throws:
SQLException
-
registerOutParameter
public NamedCallableStatement registerOutParameter(String name, int sqlType, String typeName) throws SQLException Registers every occurrence ofnameas an OUT parameter with a database-specific type name.- Throws:
SQLException
-
registerOutParameter
public NamedCallableStatement registerOutParameter(String name, SQLType sqlType) throws SQLException Registers every occurrence ofnameas an OUT parameter of the givenSQLType.- Throws:
SQLException
-
registerOutParameter
public NamedCallableStatement registerOutParameter(String name, SQLType sqlType, int scale) throws SQLException Registers every occurrence ofnameas an OUT parameter of the givenSQLTypeand scale.- Throws:
SQLException
-
registerOutParameter
public NamedCallableStatement registerOutParameter(String name, SQLType sqlType, String typeName) throws SQLException Registers every occurrence ofnameas an OUT parameter of the givenSQLTypeand type name.- Throws:
SQLException
-
getString
Reads an OUT or INOUT value.namemust occur once in the call text.- Throws:
SQLException
-
getBoolean
Reads an OUT or INOUT boolean.namemust occur once in the call text.- Throws:
SQLException
-
getByte
Reads an OUT or INOUT byte.namemust occur once in the call text.- Throws:
SQLException
-
getShort
Reads an OUT or INOUT short.namemust occur once in the call text.- Throws:
SQLException
-
getInt
Reads an OUT or INOUT int.namemust occur once in the call text.- Throws:
SQLException
-
getLong
Reads an OUT or INOUT long.namemust occur once in the call text.- Throws:
SQLException
-
getFloat
Reads an OUT or INOUT float.namemust occur once in the call text.- Throws:
SQLException
-
getDouble
Reads an OUT or INOUT double.namemust occur once in the call text.- Throws:
SQLException
-
getBigDecimal
Reads an OUT or INOUTBigDecimal.namemust occur once in the call text.- Throws:
SQLException
-
getBytes
Reads an OUT or INOUT byte array.namemust occur once in the call text.- Throws:
SQLException
-
getDate
Reads an OUT or INOUTDate.namemust occur once in the call text.- Throws:
SQLException
-
getDate
Reads an OUT or INOUTDatewith calendar.namemust occur once in the call text.- Throws:
SQLException
-
getTime
Reads an OUT or INOUTTime.namemust occur once in the call text.- Throws:
SQLException
-
getTime
Reads an OUT or INOUTTimewith calendar.namemust occur once in the call text.- Throws:
SQLException
-
getTimestamp
Reads an OUT or INOUTTimestamp.namemust occur once in the call text.- Throws:
SQLException
-
getTimestamp
Reads an OUT or INOUTTimestampwith calendar.namemust occur once in the call text.- Throws:
SQLException
-
getObject
Reads an OUT or INOUT object.namemust occur once in the call text.- Throws:
SQLException
-
getObject
Reads an OUT or INOUT object using a SQL-to-Java type map.namemust occur once in the call text.- Throws:
SQLException
-
getObject
Reads an OUT or INOUT value converted totype.namemust occur once in the call text.- Throws:
SQLException
-
getRef
Reads an OUT or INOUTRef.namemust occur once in the call text.- Throws:
SQLException
-
getBlob
Reads an OUT or INOUTBlob.namemust occur once in the call text.- Throws:
SQLException
-
getClob
Reads an OUT or INOUTClob.namemust occur once in the call text.- Throws:
SQLException
-
getArray
Reads an OUT or INOUTArray.namemust occur once in the call text.- Throws:
SQLException
-
getURL
Reads an OUT or INOUTURL.namemust occur once in the call text.- Throws:
SQLException
-
getRowId
Reads an OUT or INOUTRowId.namemust occur once in the call text.- Throws:
SQLException
-
getNClob
Reads an OUT or INOUTNClob.namemust occur once in the call text.- Throws:
SQLException
-
getSQLXML
Reads an OUT or INOUTSQLXML.namemust occur once in the call text.- Throws:
SQLException
-
getNString
Reads an OUT or INOUT national string.namemust occur once in the call text.- Throws:
SQLException
-
getCharacterStream
Reads an OUT or INOUT character stream.namemust occur once in the call text.- Throws:
SQLException
-
getNCharacterStream
Reads an OUT or INOUT national character stream.namemust occur once in the call text.- Throws:
SQLException
-
wasNull
Reports whether the last value read by agetmethod was SQL NULL.- Throws:
SQLException
-
clearParameters
Clears wrapper binding state, OUT registration bookkeeping, and underlying JDBC parameter values.- Throws:
SQLException
-
execute
Executes the call after every named parameter has been set, registered, or both.- Returns:
- same meaning as
PreparedStatement.execute() - Throws:
SQLException
-
executeQuery
Executes the call and returns the first result set, skipping update counts the same way asQueryUtils.selectFromCall(Connection, String, Object...). The returned result set does not close this statement, so OUT values can still be read.- Throws:
SQLException
-
getResultSet
Returns the current result set of the underlying call.- Throws:
SQLException
-
getMoreResults
Moves to the next result of the underlying call.- Throws:
SQLException
-
getUpdateCount
Returns the current update count of the underlying call.- Throws:
SQLException
-
addBatch
Adds the current parameter set to a batch. Every name must be an IN value: OUT and INOUT registration is rejected because batched OUT parameters are not portable.- Throws:
SQLException
-
executeBatch
Executes the JDBC batch on the underlying call.- Throws:
SQLException
-
unwrap
Returns the underlying JDBC callable statement. -
getBoundValues
Names of parameters bound withsetsince the lastclearParameters(). -
getParsedSql
Returns parsed call text transformed to JDBC placeholders. -
getParameterOrder
Returns parameter names in positional order (including repeated occurrences). -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-