Package org.mariadb.jdbc
Class ClientSidePreparedStatement
- java.lang.Object
-
- org.mariadb.jdbc.MariaDbStatement
-
- org.mariadb.jdbc.BasePrepareStatement
-
- org.mariadb.jdbc.ClientSidePreparedStatement
-
- All Implemented Interfaces:
AutoCloseable
,Cloneable
,PreparedStatement
,Statement
,Wrapper
- Direct Known Subclasses:
CallableFunctionStatement
public class ClientSidePreparedStatement extends BasePrepareStatement
-
-
Field Summary
-
Fields inherited from class org.mariadb.jdbc.BasePrepareStatement
autoGeneratedKeys, SPEC_ISO_ZONED_DATE_TIME
-
Fields inherited from class org.mariadb.jdbc.MariaDbStatement
canUseServerTimeout, closed, connection, exceptionFactory, executing, fetchSize, lock, maxRows, options, protocol, queryTimeout, results, resultSetConcurrency, resultSetScrollType
-
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
Constructors Constructor Description ClientSidePreparedStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys, ExceptionFactory exceptionFactory)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBatch()
Adds a set of parameters to thisPreparedStatement
object's batch of send.void
addBatch(String sql)
Add batch.void
clearBatch()
Clear batch.void
clearParameters()
Clears the current parameter values immediately.ClientSidePreparedStatement
clone(MariaDbConnection connection)
Clone statement.void
close()
Releases thisStatement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.boolean
execute()
Executes the SQL statement in thisPreparedStatement
object, which may be any kind of SQL statement.int[]
executeBatch()
{inheritdoc}.protected boolean
executeInternal(int fetchSize)
long[]
executeLargeBatch()
Execute batch, like executeBatch(), with returning results with long[].ResultSet
executeQuery()
Executes the SQL query in thisPreparedStatement
object and returns theResultSet
object generated by the query.int
executeUpdate()
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.ResultSetMetaData
getMetaData()
Retrieves aResultSetMetaData
object that contains information about the columns of theResultSet
object that will be returned when thisPreparedStatement
object is executed.protected int
getParameterCount()
ParameterMetaData
getParameterMetaData()
Retrieves the number, types and properties of thisPreparedStatement
object's parameters.protected ClientPrepareResult
getPrepareResult()
int[]
getServerUpdateCounts()
Non JDBC : Permit to retrieve server update counts when using option rewriteBatchedStatements.void
setParameter(int parameterIndex, ParameterHolder holder)
Set parameter.String
toString()
{inherit}.-
Methods inherited from class org.mariadb.jdbc.BasePrepareStatement
executeLargeUpdate, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setBigDecimal, setBinaryStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setBlob, setBoolean, setByte, setBytes, setCharacterStream, setCharacterStream, setCharacterStream, setClob, setClob, setClob, setDate, setDate, setDouble, setFloat, setInt, setLong, setNCharacterStream, setNCharacterStream, setNClob, setNClob, setNClob, setNString, setNull, setNull, setNull, setObject, setObject, setObject, setObject, setObject, setRef, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL
-
Methods inherited from class org.mariadb.jdbc.MariaDbStatement
cancel, checkClose, checkCloseOnCompletion, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeBatchEpilogue, executeBatchExceptionEpilogue, executeEpilogue, executeExceptionEpilogue, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeQueryPrologue, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getTimeoutSql, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, isWrapperFor, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setLocalInfileInputStream, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, setTimerTask, skipMoreResults, testExecute, unwrap
-
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, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, 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
-
-
-
-
Constructor Detail
-
ClientSidePreparedStatement
public ClientSidePreparedStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys, ExceptionFactory exceptionFactory) throws SQLException
Constructor.- Parameters:
connection
- connectionsql
- sql queryresultSetScrollType
- one of the followingResultSet
constants:ResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
, orResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency
- a concurrency type; one ofResultSet.CONCUR_READ_ONLY
orResultSet.CONCUR_UPDATABLE
autoGeneratedKeys
- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYS
orStatement.NO_GENERATED_KEYS
exceptionFactory
- exception factory- Throws:
SQLException
- exception
-
-
Method Detail
-
clone
public ClientSidePreparedStatement clone(MariaDbConnection connection) throws CloneNotSupportedException
Clone statement.- Overrides:
clone
in classBasePrepareStatement
- Parameters:
connection
- connection- Returns:
- Clone statement.
- Throws:
CloneNotSupportedException
- if any error occur.
-
execute
public boolean execute() throws SQLException
Executes the SQL statement in thisPreparedStatement
object, which may be any kind of SQL statement. Some prepared statements return multiple results; theexecute
method handles these complex statements as well as the simpler form of statements handled by the methodsexecuteQuery
andexecuteUpdate
.
Theexecute
method returns aboolean
to indicate the form of the first result. You must call either the methodgetResultSet
orgetUpdateCount
to retrieve the result; you must callgetInternalMoreResults
to move to any subsequent result(s).- Returns:
true
if the first result is aResultSet
object;false
if the first result is an update count or there is no result- Throws:
SQLException
- if a database access error occurs; this method is called on a closedPreparedStatement
or an argument is supplied to this method- See Also:
Statement.execute(java.lang.String)
,Statement.getResultSet()
,Statement.getUpdateCount()
,Statement.getMoreResults()
-
executeQuery
public ResultSet executeQuery() throws SQLException
Executes the SQL query in thisPreparedStatement
object and returns theResultSet
object generated by the query.- Returns:
- a
ResultSet
object that contains the data produced by the query; nevernull
- Throws:
SQLException
- if a database access error occurs; this method is called on a closedPreparedStatement
or the SQL statement does not return aResultSet
object
-
executeUpdate
public int executeUpdate() throws SQLException
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement. Result-set are permitted for historical reason, even if spec indicate to throw exception.- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
- Throws:
SQLException
- if a database access error occurs; this method is called on a closedPreparedStatement
-
executeInternal
protected boolean executeInternal(int fetchSize) throws SQLException
- Specified by:
executeInternal
in classBasePrepareStatement
- Throws:
SQLException
-
addBatch
public void addBatch() throws SQLException
Adds a set of parameters to thisPreparedStatement
object's batch of send.
- Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
- Since:
- 1.2
- See Also:
Statement.addBatch(java.lang.String)
-
addBatch
public void addBatch(String sql) throws SQLException
Add batch.- Specified by:
addBatch
in interfaceStatement
- Overrides:
addBatch
in classMariaDbStatement
- Parameters:
sql
- typically this is a SQLINSERT
orUPDATE
statement- Throws:
SQLException
- every time since that method is forbidden on prepareStatement- See Also:
MariaDbStatement.executeBatch()
,DatabaseMetaData.supportsBatchUpdates()
-
clearBatch
public void clearBatch()
Clear batch.- Specified by:
clearBatch
in interfaceStatement
- Overrides:
clearBatch
in classMariaDbStatement
- See Also:
MariaDbStatement.addBatch(java.lang.String)
,DatabaseMetaData.supportsBatchUpdates()
-
executeBatch
public int[] executeBatch() throws SQLException
{inheritdoc}.- Specified by:
executeBatch
in interfaceStatement
- Overrides:
executeBatch
in classMariaDbStatement
- Returns:
- an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which send were added to the batch.
- Throws:
SQLException
- if a database access error occurs, this method is called on a closedStatement
or the driver does not support batch statements. ThrowsBatchUpdateException
(a subclass ofSQLException
) if one of the send sent to the database fails to execute properly or attempts to return a result set.- See Also:
MariaDbStatement.addBatch(java.lang.String)
,DatabaseMetaData.supportsBatchUpdates()
-
getServerUpdateCounts
public int[] getServerUpdateCounts()
Non JDBC : Permit to retrieve server update counts when using option rewriteBatchedStatements.- Returns:
- an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
-
executeLargeBatch
public long[] executeLargeBatch() throws SQLException
Execute batch, like executeBatch(), with returning results with long[]. For when row count may exceed Integer.MAX_VALUE.- Specified by:
executeLargeBatch
in interfaceStatement
- Overrides:
executeLargeBatch
in classMariaDbStatement
- Returns:
- an array of update counts (one element for each command in the batch)
- Throws:
SQLException
- if a database error occur.
-
getMetaData
public ResultSetMetaData getMetaData() throws SQLException
Retrieves aResultSetMetaData
object that contains information about the columns of theResultSet
object that will be returned when thisPreparedStatement
object is executed.
Because aPreparedStatement
object is precompiled, it is possible to know about theResultSet
object that it will return without having to execute it. Consequently, it is possible to invoke the methodgetMetaData
on aPreparedStatement
object rather than waiting to execute it and then invoking theResultSet.getMetaData
method on theResultSet
object that is returned.- Returns:
- the description of a
ResultSet
object's columns ornull
if the driver cannot return aResultSetMetaData
object - Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
-
setParameter
public void setParameter(int parameterIndex, ParameterHolder holder) throws SQLException
Set parameter.- Specified by:
setParameter
in classBasePrepareStatement
- Parameters:
parameterIndex
- indexholder
- parameter holder- Throws:
SQLException
- if index position doesn't correspond to query parameters
-
getParameterMetaData
public ParameterMetaData getParameterMetaData() throws SQLException
Retrieves the number, types and properties of thisPreparedStatement
object's parameters.- Specified by:
getParameterMetaData
in interfacePreparedStatement
- Specified by:
getParameterMetaData
in classBasePrepareStatement
- Returns:
- a
ParameterMetaData
object that contains information about the number, types and properties for each parameter marker of thisPreparedStatement
object - Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
- Since:
- 1.4
- See Also:
ParameterMetaData
-
clearParameters
public void clearParameters()
Clears the current parameter values immediately.In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method
clearParameters
.
-
close
public void close() throws SQLException
Description copied from class:MariaDbStatement
Releases thisStatement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources. Calling the methodclose
on aStatement
object that is already closed has no effect. Note:When aStatement
object is closed, its currentResultSet
object, if one exists, is also closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Overrides:
close
in classMariaDbStatement
- Throws:
SQLException
- if a database access error occurs
-
getParameterCount
protected int getParameterCount()
-
getPrepareResult
protected ClientPrepareResult getPrepareResult()
-
-