Package org.postgresql.jdbc
Class PgPreparedStatement
java.lang.Object
org.postgresql.jdbc.PgStatement
org.postgresql.jdbc.PgPreparedStatement
- All Implemented Interfaces:
AutoCloseable
,PreparedStatement
,Statement
,Wrapper
,BaseStatement
,PGStatement
- Direct Known Subclasses:
PgCallableStatement
-
Nested Class Summary
Nested classes/interfaces inherited from class org.postgresql.jdbc.PgStatement
PgStatement.StatementResultHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TimeZone
protected final ParameterList
protected final CachedQuery
Fields inherited from class org.postgresql.jdbc.PgStatement
adaptiveFetch, batchParameters, batchStatements, concurrency, connection, fetchdirection, fetchSize, firstUnclosedResult, generatedKeys, lock, maxFieldSize, maxrows, mPrepareThreshold, replaceProcessingEnabled, result, resultsettype, timeout, wantsGeneratedKeysAlways, wantsGeneratedKeysOnce, warnings
Fields inherited from interface org.postgresql.PGStatement
DATE_NEGATIVE_INFINITY, DATE_NEGATIVE_SMALLER_INFINITY, DATE_POSITIVE_INFINITY, DATE_POSITIVE_SMALLER_INFINITY
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
-
Constructor Summary
ConstructorsConstructorDescriptionPgPreparedStatement
(PgConnection connection, String sql, int rsType, int rsConcurrency, int rsHoldability) PgPreparedStatement
(PgConnection connection, CachedQuery query, int rsType, int rsConcurrency, int rsHoldability) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBatch()
void
private static String
protected void
bindBytes
(int paramIndex, byte[] b, int oid) protected void
bindLiteral
(int paramIndex, String s, int oid) Note if s is a String it should be escaped by the caller to avoid SQL injection attacks.private void
bindString
(int paramIndex, String s, int oid) This version is for values that should turn into strings e.g.private static PSQLException
cannotCastException
(String fromType, String toType) private static PSQLException
cannotCastException
(String fromType, String toType, Exception cause) private static BigDecimal
castToBigDecimal
(Object in, int scale) private static double
castToDouble
(Object in) private static float
castToFloat
(Object in) private static int
private static long
castToLong
(Object in) private static short
castToShort
(Object in) private static String
castToString
(Object in) void
void
This is guaranteed to be called exactly once even in case of concurrentPgStatement.close()
calls.protected long
createBlob
(int i, InputStream inputStream, long length) createParameterMetaData
(BaseConnection conn, int[] oids) boolean
execute()
boolean
int[]
long
executeQuery
(String sql) int
int
executeUpdate
(String sql) boolean
executeWithFlags
(int flags) Execute a prepared query, passing additional query flags.private Class<?>
getArrayType
(Class<?> type) private Calendar
private int
protected boolean
isOneShotQuery
(CachedQuery cachedQuery) Returns true if query is unlikely to be reused.boolean
Checks if this statement will be executed as a server-prepared statement.(package private) final int
private String
readerToString
(Reader value, int maxLength) void
void
setAsciiStream
(int parameterIndex, InputStream value) void
setAsciiStream
(int parameterIndex, InputStream x, int length) void
setAsciiStream
(int parameterIndex, InputStream value, long length) void
setBigDecimal
(int parameterIndex, BigDecimal x) void
setBinaryStream
(int parameterIndex, InputStream value) void
setBinaryStream
(int parameterIndex, InputStream x, int length) void
setBinaryStream
(int parameterIndex, InputStream value, long length) void
setBlob
(int parameterIndex, InputStream inputStream) void
setBlob
(int parameterIndex, InputStream inputStream, long length) void
void
setBoolean
(int parameterIndex, boolean x) void
setByte
(int parameterIndex, byte x) void
setBytes
(int parameterIndex, byte[] x) private void
setByteStreamWriter
(int parameterIndex, ByteStreamWriter x) void
setCharacterStream
(int parameterIndex, Reader value) void
setCharacterStream
(int i, Reader x, int length) void
setCharacterStream
(int parameterIndex, Reader value, long length) private void
setCharacterStreamPost71
(int parameterIndex, InputStream x, int length, String encoding) void
void
void
void
void
private void
void
setDouble
(int parameterIndex, double x) void
setFloat
(int parameterIndex, float x) void
setInt
(int parameterIndex, int x) void
setLong
(int parameterIndex, long x) private void
void
setNCharacterStream
(int parameterIndex, Reader value) void
setNCharacterStream
(int parameterIndex, Reader value, long length) void
void
void
void
setNString
(int parameterIndex, String value) void
setNull
(int parameterIndex, int sqlType) void
private void
void
void
void
void
void
private <A> void
setObjectArray
(int parameterIndex, A in) private void
setPGobject
(int parameterIndex, PGobject x) void
void
void
setShort
(int parameterIndex, short x) void
void
protected void
void
void
private void
private void
setTime
(int i, OffsetTime offsetTime) void
setTimestamp
(int parameterIndex, Timestamp x) void
setTimestamp
(int i, Timestamp t, Calendar cal) private void
setTimestamp
(int i, LocalDateTime localDateTime) private void
setTimestamp
(int i, OffsetDateTime offsetDateTime) void
setUnicodeStream
(int parameterIndex, InputStream x, int length) void
private void
toString()
Returns the SQL statement with the current template values substituted.protected void
Methods inherited from class org.postgresql.jdbc.PgStatement
addWarning, cancel, cancelIfStillNeeded, checkClosed, checkCompletion, checkNoResultUpdate, clearBatch, clearWarnings, close, closeForNextExecution, closeOnCompletion, createBatchHandler, createDriverResultSet, createResultSet, execute, execute, execute, execute, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeUpdate, executeUpdate, executeUpdate, executeWithFlags, executeWithFlags, getAdaptiveFetch, getConnection, getFetchDirection, getFetchingCursorName, getFetchSize, getForceBinaryTransfer, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getLastOID, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getPGConnection, getPrepareThreshold, getQueryTimeout, getQueryTimeoutMs, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getSingleResultSet, getTimestampUtils, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, setAdaptiveFetch, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setPrepareThreshold, setQueryTimeout, setQueryTimeoutMs, setUseServerPrepare, unwrap, wantsHoldableResultSet, wantsScrollableResultSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Statement
cancel, clearBatch, clearWarnings, close, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Field Details
-
preparedQuery
-
preparedParameters
-
defaultTimeZone
-
-
Constructor Details
-
PgPreparedStatement
PgPreparedStatement(PgConnection connection, String sql, int rsType, int rsConcurrency, int rsHoldability) throws SQLException - Throws:
SQLException
-
PgPreparedStatement
PgPreparedStatement(PgConnection connection, CachedQuery query, int rsType, int rsConcurrency, int rsHoldability) throws SQLException - Throws:
SQLException
-
-
Method Details
-
maximumNumberOfParameters
final int maximumNumberOfParameters() -
executeQuery
- Specified by:
executeQuery
in interfaceStatement
- Overrides:
executeQuery
in classPgStatement
- Throws:
SQLException
-
executeQuery
- Specified by:
executeQuery
in interfacePreparedStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Overrides:
executeUpdate
in classPgStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfacePreparedStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfacePreparedStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Overrides:
execute
in classPgStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfacePreparedStatement
- Throws:
SQLException
-
executeWithFlags
Description copied from interface:BaseStatement
Execute a prepared query, passing additional query flags.- Specified by:
executeWithFlags
in interfaceBaseStatement
- Overrides:
executeWithFlags
in classPgStatement
- Parameters:
flags
- additionalQueryExecutor
flags for execution; these are bitwise-ORed into the default flags.- Returns:
- true if there is a result set
- Throws:
SQLException
- if something goes wrong.
-
isOneShotQuery
Description copied from class:PgStatement
Returns true if query is unlikely to be reused.- Overrides:
isOneShotQuery
in classPgStatement
- Parameters:
cachedQuery
- to check (null if current query)- Returns:
- true if query is unlikely to be reused
-
closeImpl
Description copied from class:PgStatement
This is guaranteed to be called exactly once even in case of concurrentPgStatement.close()
calls.- Overrides:
closeImpl
in classPgStatement
- Throws:
SQLException
- in case of error
-
setNull
- Specified by:
setNull
in interfacePreparedStatement
- Throws:
SQLException
-
setBoolean
- Specified by:
setBoolean
in interfacePreparedStatement
- Throws:
SQLException
-
setByte
- Specified by:
setByte
in interfacePreparedStatement
- Throws:
SQLException
-
setShort
- Specified by:
setShort
in interfacePreparedStatement
- Throws:
SQLException
-
setInt
- Specified by:
setInt
in interfacePreparedStatement
- Throws:
SQLException
-
setLong
- Specified by:
setLong
in interfacePreparedStatement
- Throws:
SQLException
-
setFloat
- Specified by:
setFloat
in interfacePreparedStatement
- Throws:
SQLException
-
setDouble
- Specified by:
setDouble
in interfacePreparedStatement
- Throws:
SQLException
-
setBigDecimal
- Specified by:
setBigDecimal
in interfacePreparedStatement
- Throws:
SQLException
-
setString
- Specified by:
setString
in interfacePreparedStatement
- Throws:
SQLException
-
getStringType
private int getStringType() -
setString
- Throws:
SQLException
-
setBytes
- Specified by:
setBytes
in interfacePreparedStatement
- Throws:
SQLException
-
setByteStreamWriter
- Throws:
SQLException
-
setDate
- Specified by:
setDate
in interfacePreparedStatement
- Throws:
SQLException
-
setTime
- Specified by:
setTime
in interfacePreparedStatement
- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestamp
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStreamPost71
private void setCharacterStreamPost71(int parameterIndex, InputStream x, int length, String encoding) throws SQLException - Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setUnicodeStream
- Specified by:
setUnicodeStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
clearParameters
- Specified by:
clearParameters
in interfacePreparedStatement
- Throws:
SQLException
-
setPGobject
- Throws:
SQLException
-
setMap
- Throws:
SQLException
-
setNumber
- Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object in, int targetSqlType, int scale) throws SQLException - Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
getArrayType
-
setObjectArray
- Throws:
SQLException
-
asString
- Throws:
SQLException
-
castToInt
- Throws:
SQLException
-
castToShort
- Throws:
SQLException
-
castToLong
- Throws:
SQLException
-
castToFloat
- Throws:
SQLException
-
castToDouble
- Throws:
SQLException
-
castToBigDecimal
- Throws:
SQLException
-
castToString
- Throws:
SQLException
-
cannotCastException
-
cannotCastException
-
setObject
- Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setObject
- Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
toString
Returns the SQL statement with the current template values substituted. -
bindLiteral
Note if s is a String it should be escaped by the caller to avoid SQL injection attacks. It is not done here for efficiency reasons as most calls to this method do not require escaping as the source of the string is known safe (i.e.Integer.toString()
)- Parameters:
paramIndex
- parameter indexs
- value (the value should already be escaped)oid
- type oid- Throws:
SQLException
- if something goes wrong
-
bindBytes
- Throws:
SQLException
-
bindString
This version is for values that should turn into strings e.g. setString directly calls bindString with no escaping; the per-protocol ParameterList does escaping as needed.- Parameters:
paramIndex
- parameter indexs
- valueoid
- type oid- Throws:
SQLException
- if something goes wrong
-
isUseServerPrepare
public boolean isUseServerPrepare()Description copied from interface:PGStatement
Checks if this statement will be executed as a server-prepared statement. A return value oftrue
indicates that the next execution of the statement will be done as a server-prepared statement, assuming the underlying protocol supports it.- Specified by:
isUseServerPrepare
in interfacePGStatement
- Overrides:
isUseServerPrepare
in classPgStatement
- Returns:
- true if the next reuse of this statement will use a server-prepared statement
-
addBatch
- Specified by:
addBatch
in interfaceStatement
- Overrides:
addBatch
in classPgStatement
- Throws:
SQLException
-
addBatch
- Specified by:
addBatch
in interfacePreparedStatement
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfacePreparedStatement
- Throws:
SQLException
-
setArray
- Specified by:
setArray
in interfacePreparedStatement
- Throws:
SQLException
-
createBlob
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
readerToString
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNull
- Specified by:
setNull
in interfacePreparedStatement
- Throws:
SQLException
-
setRef
- Specified by:
setRef
in interfacePreparedStatement
- Throws:
SQLException
-
setDate
- Specified by:
setDate
in interfacePreparedStatement
- Throws:
SQLException
-
setTime
- Specified by:
setTime
in interfacePreparedStatement
- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestamp
in interfacePreparedStatement
- Throws:
SQLException
-
setDate
- Throws:
SQLException
-
setTime
- Throws:
SQLException
-
setTime
- Throws:
SQLException
-
setTimestamp
- Throws:
SQLException
-
setTimestamp
- Throws:
SQLException
-
createParameterMetaData
public ParameterMetaData createParameterMetaData(BaseConnection conn, int[] oids) throws SQLException - Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException - Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setObject
- Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setRowId
- Specified by:
setRowId
in interfacePreparedStatement
- Throws:
SQLException
-
setNString
- Specified by:
setNString
in interfacePreparedStatement
- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setSQLXML
- Specified by:
setSQLXML
in interfacePreparedStatement
- Throws:
SQLException
-
setUuid
- Throws:
SQLException
-
setURL
- Specified by:
setURL
in interfacePreparedStatement
- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatch
in interfaceStatement
- Overrides:
executeBatch
in classPgStatement
- Throws:
SQLException
-
getDefaultCalendar
-
getParameterMetaData
- Specified by:
getParameterMetaData
in interfacePreparedStatement
- Throws:
SQLException
-
transformQueriesAndParameters
- Overrides:
transformQueriesAndParameters
in classPgStatement
- Throws:
SQLException
-