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 TimeZoneprotected final ParameterListprotected final CachedQueryFields 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, warningsFields inherited from interface org.postgresql.PGStatement
DATE_NEGATIVE_INFINITY, DATE_NEGATIVE_SMALLER_INFINITY, DATE_POSITIVE_INFINITY, DATE_POSITIVE_SMALLER_INFINITYFields 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 TypeMethodDescriptionvoidaddBatch()voidprivate static Stringprotected voidbindBytes(int paramIndex, byte[] b, int oid) protected voidbindLiteral(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 voidbindString(int paramIndex, String s, int oid) This version is for values that should turn into strings e.g.private static PSQLExceptioncannotCastException(String fromType, String toType) private static PSQLExceptioncannotCastException(String fromType, String toType, Exception cause) private static BigDecimalcastToBigDecimal(Object in, int scale) private static doublecastToDouble(Object in) private static floatcastToFloat(Object in) private static intprivate static longcastToLong(Object in) private static shortcastToShort(Object in) private static StringcastToString(Object in) voidvoidThis is guaranteed to be called exactly once even in case of concurrentPgStatement.close()calls.protected longcreateBlob(int i, InputStream inputStream, long length) createParameterMetaData(BaseConnection conn, int[] oids) booleanexecute()booleanint[]longA Prepared SQL query is executed and its ResultSet is returnedexecuteQuery(String sql) intintexecuteUpdate(String sql) booleanexecuteWithFlags(int flags) Execute a prepared query, passing additional query flags.private static Class<?> getArrayType(Class<?> type) private Calendarprivate intprotected booleanisOneShotQuery(CachedQuery cachedQuery) Returns true if query is unlikely to be reused.booleanChecks if this statement will be executed as a server-prepared statement.(package private) final intprivate static StringreaderToString(Reader value, int maxLength) voidvoidsetAsciiStream(int parameterIndex, InputStream value) voidsetAsciiStream(int parameterIndex, InputStream x, int length) voidsetAsciiStream(int parameterIndex, InputStream value, long length) voidsetBigDecimal(int parameterIndex, BigDecimal x) voidsetBinaryStream(int parameterIndex, InputStream value) voidsetBinaryStream(int parameterIndex, InputStream x, int length) voidsetBinaryStream(int parameterIndex, InputStream value, long length) voidsetBlob(int parameterIndex, InputStream inputStream) voidsetBlob(int parameterIndex, InputStream inputStream, long length) voidvoidsetBoolean(int parameterIndex, boolean x) voidsetByte(int parameterIndex, byte x) voidsetBytes(int parameterIndex, byte[] x) private voidsetByteStreamWriter(int parameterIndex, ByteStreamWriter x) voidsetCharacterStream(int parameterIndex, Reader value) voidsetCharacterStream(int i, Reader x, int length) voidsetCharacterStream(int parameterIndex, Reader value, long length) private voidsetCharacterStreamPost71(int parameterIndex, InputStream x, int length, String encoding) voidvoidvoidvoidvoidprivate voidvoidsetDouble(int parameterIndex, double x) voidsetFloat(int parameterIndex, float x) voidsetInt(int parameterIndex, int x) voidsetLong(int parameterIndex, long x) private voidvoidsetNCharacterStream(int parameterIndex, Reader value) voidsetNCharacterStream(int parameterIndex, Reader value, long length) voidvoidvoidvoidsetNString(int parameterIndex, String value) voidsetNull(int parameterIndex, int sqlType) voidprivate voidvoidvoidvoidvoidvoidprivate <A> voidsetObjectArray(int parameterIndex, A in) private voidsetPGobject(int parameterIndex, PGobject x) voidvoidvoidsetShort(int parameterIndex, short x) voidvoidprotected voidvoidvoidprivate voidprivate voidsetTime(int i, OffsetTime offsetTime) voidsetTimestamp(int parameterIndex, Timestamp x) voidsetTimestamp(int i, Timestamp t, Calendar cal) private voidsetTimestamp(int i, LocalDateTime localDateTime) private voidsetTimestamp(int i, OffsetDateTime offsetDateTime) voidsetUnicodeStream(int parameterIndex, InputStream x, int length) voidprivate voidtoString()Returns the SQL statement with the current template values substituted.protected voidMethods 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, wantsScrollableResultSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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, setQueryTimeoutMethods 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:
executeQueryin interfaceStatement- Overrides:
executeQueryin classPgStatement- Throws:
SQLException
-
executeQuery
A Prepared SQL query is executed and its ResultSet is returned- Specified by:
executeQueryin interfacePreparedStatement- Returns:
- a ResultSet that contains the data produced by the * query - never null
- Throws:
SQLException- if a database access error occurs
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classPgStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfacePreparedStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfacePreparedStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Overrides:
executein classPgStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfacePreparedStatement- Throws:
SQLException
-
executeWithFlags
Description copied from interface:BaseStatementExecute a prepared query, passing additional query flags.- Specified by:
executeWithFlagsin interfaceBaseStatement- Overrides:
executeWithFlagsin classPgStatement- Parameters:
flags- additionalQueryExecutorflags 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:PgStatementReturns true if query is unlikely to be reused.- Overrides:
isOneShotQueryin classPgStatement- Parameters:
cachedQuery- to check (null if current query)- Returns:
- true if query is unlikely to be reused
-
closeImpl
Description copied from class:PgStatementThis is guaranteed to be called exactly once even in case of concurrentPgStatement.close()calls.- Overrides:
closeImplin classPgStatement- Throws:
SQLException- in case of error
-
setNull
- Specified by:
setNullin interfacePreparedStatement- Throws:
SQLException
-
setBoolean
- Specified by:
setBooleanin interfacePreparedStatement- Throws:
SQLException
-
setByte
- Specified by:
setBytein interfacePreparedStatement- Throws:
SQLException
-
setShort
- Specified by:
setShortin interfacePreparedStatement- Throws:
SQLException
-
setInt
- Specified by:
setIntin interfacePreparedStatement- Throws:
SQLException
-
setLong
- Specified by:
setLongin interfacePreparedStatement- Throws:
SQLException
-
setFloat
- Specified by:
setFloatin interfacePreparedStatement- Throws:
SQLException
-
setDouble
- Specified by:
setDoublein interfacePreparedStatement- Throws:
SQLException
-
setBigDecimal
- Specified by:
setBigDecimalin interfacePreparedStatement- Throws:
SQLException
-
setString
- Specified by:
setStringin interfacePreparedStatement- Throws:
SQLException
-
getStringType
private int getStringType() -
setString
- Throws:
SQLException
-
setBytes
- Specified by:
setBytesin interfacePreparedStatement- Throws:
SQLException
-
setByteStreamWriter
- Throws:
SQLException
-
setDate
- Specified by:
setDatein interfacePreparedStatement- Throws:
SQLException
-
setTime
- Specified by:
setTimein interfacePreparedStatement- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestampin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStreamPost71
private void setCharacterStreamPost71(int parameterIndex, InputStream x, int length, String encoding) throws SQLException - Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setUnicodeStream
- Specified by:
setUnicodeStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
clearParameters
- Specified by:
clearParametersin 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:
setObjectin 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:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setObject
- Specified by:
setObjectin 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:PGStatementChecks if this statement will be executed as a server-prepared statement. A return value oftrueindicates that the next execution of the statement will be done as a server-prepared statement, assuming the underlying protocol supports it.- Specified by:
isUseServerPreparein interfacePGStatement- Overrides:
isUseServerPreparein classPgStatement- Returns:
- true if the next reuse of this statement will use a server-prepared statement
-
addBatch
- Specified by:
addBatchin interfaceStatement- Overrides:
addBatchin classPgStatement- Throws:
SQLException
-
addBatch
- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfacePreparedStatement- Throws:
SQLException
-
setArray
- Specified by:
setArrayin interfacePreparedStatement- Throws:
SQLException
-
createBlob
- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
readerToString
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setNull
- Specified by:
setNullin interfacePreparedStatement- Throws:
SQLException
-
setRef
- Specified by:
setRefin interfacePreparedStatement- Throws:
SQLException
-
setDate
- Specified by:
setDatein interfacePreparedStatement- Throws:
SQLException
-
setTime
- Specified by:
setTimein interfacePreparedStatement- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestampin 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:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setObject
- Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setRowId
- Specified by:
setRowIdin interfacePreparedStatement- Throws:
SQLException
-
setNString
- Specified by:
setNStringin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setSQLXML
- Specified by:
setSQLXMLin interfacePreparedStatement- Throws:
SQLException
-
setUuid
- Throws:
SQLException
-
setURL
- Specified by:
setURLin interfacePreparedStatement- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatchin interfaceStatement- Overrides:
executeBatchin classPgStatement- Throws:
SQLException
-
getDefaultCalendar
-
getParameterMetaData
- Specified by:
getParameterMetaDatain interfacePreparedStatement- Throws:
SQLException
-
transformQueriesAndParameters
- Overrides:
transformQueriesAndParametersin classPgStatement- Throws:
SQLException
-