Class ServerSidePreparedStatement

All Implemented Interfaces:
AutoCloseable, Cloneable, PreparedStatement, Statement, Wrapper
Direct Known Subclasses:
CallableProcedureStatement

public class ServerSidePreparedStatement extends BasePrepareStatement implements Cloneable
  • Field Details

  • Constructor Details

    • ServerSidePreparedStatement

      public ServerSidePreparedStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys, ExceptionFactory exceptionFactory) throws SQLException
      Constructor for creating Server prepared statement.
      Parameters:
      connection - current connection
      sql - Sql String to prepare
      resultSetScrollType - one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
      resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
      autoGeneratedKeys - a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
      exceptionFactory - Exception factory
      Throws:
      SQLException - exception
  • Method Details

    • clone

      Clone statement.
      Overrides:
      clone in class BasePrepareStatement
      Parameters:
      connection - connection
      Returns:
      Clone statement.
      Throws:
      CloneNotSupportedException - if any error occur.
    • prepare

      private void prepare(String sql) throws SQLException
      Throws:
      SQLException
    • setMetaFromResult

      private void setMetaFromResult()
    • setParameter

      public void setParameter(int parameterIndex, ParameterHolder holder) throws SQLException
      Specified by:
      setParameter in class BasePrepareStatement
      Throws:
      SQLException
    • addBatch

      public void addBatch() throws SQLException
      Specified by:
      addBatch in interface PreparedStatement
      Throws:
      SQLException
    • addBatch

      public void addBatch(String sql) throws SQLException
      Add batch.
      Specified by:
      addBatch in interface Statement
      Overrides:
      addBatch in class MariaDbStatement
      Parameters:
      sql - typically this is a SQL INSERT or UPDATE statement
      Throws:
      SQLException - every time since that method is forbidden on prepareStatement
      See Also:
    • clearBatch

      public void clearBatch()
      Description copied from class: MariaDbStatement
      Empties this Statement object's current list of SQL send.
      Specified by:
      clearBatch in interface Statement
      Overrides:
      clearBatch in class MariaDbStatement
      See Also:
    • getParameterMetaData

      public ParameterMetaData getParameterMetaData() throws SQLException
      Description copied from class: BasePrepareStatement
      Retrieves the number, types and properties of this PreparedStatement object's parameters.
      Specified by:
      getParameterMetaData in interface PreparedStatement
      Specified by:
      getParameterMetaData in class BasePrepareStatement
      Returns:
      a ParameterMetaData object that contains information about the number, types and properties for each parameter marker of this PreparedStatement object
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
      See Also:
    • getMetaData

      public ResultSetMetaData getMetaData() throws SQLException
      Specified by:
      getMetaData in interface PreparedStatement
      Throws:
      SQLException
    • executeBatch

      public int[] executeBatch() throws SQLException
      Submits a batch of send to the database for execution and if all send execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the send in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following:
      1. A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
      2. A value of SUCCESS_NO_INFO -- indicates that the command was processed successfully but that the number of rows affected is unknown. If one of the send in a batch update fails to execute properly, this method throws a BatchUpdateException , and a JDBC driver may or may not continue to process the remaining send in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process send or never continuing to process send. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are send in the batch, and at least one of the elements will be the following:
      3. A value of EXECUTE_FAILED -- indicates that the command failed to execute successfully and occurs only if a driver continues to process send after a command fails

      The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess send in a batch update after a BatchUpdateException object has been thrown.

      Specified by:
      executeBatch in interface Statement
      Overrides:
      executeBatch in class MariaDbStatement
      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 closed Statement or the driver does not support batch statements. Throws BatchUpdateException (a subclass of SQLException) if one of the send sent to the database fails to execute properly or attempts to return a result set.
      Since:
      1.3
      See Also:
    • 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 interface Statement
      Overrides:
      executeLargeBatch in class MariaDbStatement
      Returns:
      an array of update counts (one element for each command in the batch)
      Throws:
      SQLException - if a database error occur.
    • executeBatchInternal

      private void executeBatchInternal(int queryParameterSize) throws SQLException
      Throws:
      SQLException
    • executeQueryPrologue

      private void executeQueryPrologue(ServerPrepareResult serverPrepareResult) throws SQLException
      Throws:
      SQLException
    • executeQuery

      public ResultSet executeQuery() throws SQLException
      Specified by:
      executeQuery in interface PreparedStatement
      Throws:
      SQLException
    • executeUpdate

      public int executeUpdate() throws SQLException
      Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; 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.
      Specified by:
      executeUpdate in interface PreparedStatement
      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 closed PreparedStatement
    • clearParameters

      public void clearParameters()
      Specified by:
      clearParameters in interface PreparedStatement
    • execute

      public boolean execute() throws SQLException
      Specified by:
      execute in interface PreparedStatement
      Throws:
      SQLException
    • validParameters

      protected void validParameters() throws SQLException
      Throws:
      SQLException
    • executeInternal

      protected boolean executeInternal(int fetchSize) throws SQLException
      Specified by:
      executeInternal in class BasePrepareStatement
      Throws:
      SQLException
    • close

      public void close() throws SQLException
      Releases this Statement 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 method close on a Statement object that is already closed has no effect.

      Note:When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Statement
      Overrides:
      close in class MariaDbStatement
      Throws:
      SQLException - if a database access error occurs
    • getParameterCount

      protected int getParameterCount()
    • toString

      public String toString()
      Return sql String value.
      Overrides:
      toString in class Object
      Returns:
      String representation
    • getServerThreadId

      public long getServerThreadId()
      Permit to retrieve current connection thread id, or -1 if unknown.
      Returns:
      current connection thread id.