Class JtdsStatement

java.lang.Object
net.sourceforge.jtds.jdbc.JtdsStatement
All Implemented Interfaces:
AutoCloseable, Statement, Wrapper
Direct Known Subclasses:
JtdsPreparedStatement

public class JtdsStatement extends Object implements Statement
jTDS implementation of the java.sql.Statement interface.

NB. As allowed by the JDBC standard and like most other drivers, this implementation only allows one open result set at a time.

Implementation notes:

I experimented with allowing multiple open result sets as supported by the original jTDS but rejected this approach for the following reasons:

  1. It is more difficult to ensure that there are no memory leaks and that cursors are closed if multiple open sets are allowed.
  2. The use of one result set allows cursor and non cursor result sets to be derived from exeuteQuery() or execute() and getResultSet() in the same way that other drivers do.
In the event of an IO failure the setClosed() method forces this statement and associated result set to close preventing the propagation of errors. This class includes a finalize method which increases the chances of the statement being closed tidly in a pooled environment where the user has forgotten to explicitly close the statement before it goes out of scope.
Author:
Mike Hutchinson, Holger Rehn
See Also:
  • Field Details

    • GENKEYCOL

      static final String GENKEYCOL
      Column name to be used for retrieving generated keys from the server: "_JTDS_GENE_RATED_KEYS_"
      See Also:
    • RETURN_GENERATED_KEYS

      static final int RETURN_GENERATED_KEYS
      See Also:
    • NO_GENERATED_KEYS

      static final int NO_GENERATED_KEYS
      See Also:
    • CLOSE_CURRENT_RESULT

      static final int CLOSE_CURRENT_RESULT
      See Also:
    • KEEP_CURRENT_RESULT

      static final int KEEP_CURRENT_RESULT
      See Also:
    • CLOSE_ALL_RESULTS

      static final int CLOSE_ALL_RESULTS
      See Also:
    • BOOLEAN

      static final int BOOLEAN
      See Also:
    • SUCCESS_NO_INFO

      static final Integer SUCCESS_NO_INFO
    • EXECUTE_FAILED

      static final Integer EXECUTE_FAILED
    • DEFAULT_FETCH_SIZE

      static final int DEFAULT_FETCH_SIZE
      See Also:
    • connection

      protected JtdsConnection connection
      The connection owning this statement object.
    • tds

      protected TdsCore tds
      The TDS object used for server access.
    • queryTimeout

      protected int queryTimeout
      The read query timeout in seconds
    • currentResult

      protected JtdsResultSet currentResult
      The current ResultSet.
    • updateCount

      private int updateCount
      The current update count.
    • fetchDirection

      protected int fetchDirection
      The fetch direction for result sets.
    • resultSetType

      protected int resultSetType
      The type of result sets created by this statement.
    • resultSetConcurrency

      protected int resultSetConcurrency
      The concurrency of result sets created by this statement.
    • fetchSize

      protected int fetchSize
      The fetch size (default 100, only used by cursor ResultSets).
    • cursorName

      protected String cursorName
      The cursor name to be used for positioned updates.
    • maxFieldSize

      protected int maxFieldSize
      The maximum field size (not used at present).
    • maxRows

      protected int maxRows
      The maximum number of rows to return (not used at present).
    • escapeProcessing

      protected boolean escapeProcessing
      True if SQL statements should be preprocessed.
    • messages

      protected final SQLDiagnostic messages
      SQL Diagnostic exceptions and warnings.
    • batchValues

      protected ArrayList batchValues
      Batched SQL Statement array.
    • genKeyResultSet

      protected CachedResultSet genKeyResultSet
      Dummy result set for getGeneratedKeys.
    • resultQueue

      protected final LinkedList resultQueue
      List of queued results (update counts, possibly followed by a ResultSet).
    • openResultSets

      protected ArrayList openResultSets
      List of open result sets.
    • colMetaData

      protected ColInfo[] colMetaData
      The cached column meta data.
    • _Closed

      private final AtomicInteger _Closed
      0 - this statement is open
      1 - this statement is currently being closed
      2 - this statement is closed
  • Constructor Details

    • JtdsStatement

      JtdsStatement(JtdsConnection connection, int resultSetType, int resultSetConcurrency) throws SQLException
      Construct a new Statement object.
      Parameters:
      connection - The parent connection.
      resultSetType - The result set type for example TYPE_FORWARD_ONLY.
      resultSetConcurrency - The concurrency for example CONCUR_READ_ONLY.
      Throws:
      SQLException
  • Method Details