net.sourceforge.jtds.jdbc
Class ConnectionJDBC2

java.lang.Object
  |
  +--net.sourceforge.jtds.jdbc.ConnectionJDBC2
All Implemented Interfaces:
java.sql.Connection
Direct Known Subclasses:
ConnectionJDBC3

public class ConnectionJDBC2
extends java.lang.Object
implements java.sql.Connection

jTDS implementation of the java.sql.Connection interface.

Implementation notes:

  1. Environment setting code carried over from old jTDS otherwise generally a new implementation of Connection.
  2. Connection properties and SQLException text messages are loaded from a properties file.
  3. Character set choices are also loaded from a resource file and the original Encoder class has gone.
  4. Prepared SQL statements are converted to procedures in the prepareSQL method.
  5. Use of Stored procedures is optional and controlled via connection property.
  6. This Connection object maintains a table of weak references to associated statements. This allows the connection object to control the statements (for example to close them) but without preventing them being garbage collected in a pooled environment.

Version:
$Id: ConnectionJDBC2.java,v 1.76 2005/03/18 11:46:45 alin_sinpalean Exp $
Author:
Mike Hutchinson, Alin Sinpalean

Inner Class Summary
protected static class ConnectionJDBC2.ProcEntry
          Class used to describe a cached stored procedure for prepared statements.
 
Field Summary
private  java.lang.String appName
          The application name.
private  boolean autoCommit
          Default auto commit state.
private  TdsCore baseTds
          The cored TDS protocol object.
private  int batchSize
          The maximum size of a batch.
private  CharsetInfo charsetInfo
          Java charset for encoding.
private  boolean charsetSpecified
          True if user specifies an explicit charset.
private  boolean closed
          True if this connection is closed.
private  byte[] collation
          SQL Server 2000 collation.
private  java.lang.String currentDatabase
          The current database name.
private  int databaseMajorVersion
          The major version number eg 11.
private  int databaseMinorVersion
          The minor version number eg 92.
private  java.lang.String databaseName
          The requested database name.
private  java.lang.String databaseProductName
          The database product name eg SQL SERVER.
private  java.lang.String databaseProductVersion
          The product version eg 11.92.
private  java.lang.String domainName
          The Windows Domain name.
private  java.lang.String instanceName
          The SQL Server instance.
private  java.lang.String language
          The server message language.
private  boolean lastUpdateCount
          Only return the last update count.
private  long lobBuffer
          The amount of LOB data to buffer in memory.
private  int loginTimeout
          Login timeout value in seconds or 0.
private  java.lang.String macAddress
          The client MAC Address.
private  int maxPrecision
          Maximum decimal precision.
private  int maxStatements
          The maximum number of statements to keep open.
private  SQLDiagnostic messages
          Diagnostc messages for this connection.
private  Semaphore mutex
          Mutual exclusion lock to control access to connection.
private  boolean namedPipe
          Use named pipe IPC instead of TCP/IP sockets.
private  int netPacketSize
          The initial network packet size.
private  int packetSize
          User requested packet size.
private  java.lang.String password
          The user password.
private  int portNumber
          The server port number.
private  int prepareSql
          Method for preparing SQL used in Prepared Statements.
private  java.util.ArrayList procInTran
          Procedures in this transaction.
private  java.lang.String progName
          The program name.
private  boolean readOnly
          True if this connection is read only.
private  int rowCount
          Connection's current rowcount limit.
private  java.lang.String serverCharset
          The server character set.
private  java.lang.String serverName
          The server host name.
private  int serverType
          The make of SQL Server (sybase/microsoft).
private  SharedSocket socket
          The network TCP/IP socket.
private  int spSequenceNo
          Stored procedure unique ID number.
private static java.lang.String SQL_SERVER_65_CHARSET_QUERY
          SQL query to determine the server charset on MS SQL Server 6.5.
private  java.lang.String SQL_SERVER_INITIAL_SQL
          SQL Server initial connection string.
private  java.lang.String ssl
          SSL setting.
private  StatementCache statementCache
          Statement cache.
private  java.util.ArrayList statements
          List of statements associated with this connection.
private  java.lang.String SYBASE_INITIAL_SQL
          Sybase initial connection string.
private static java.lang.String SYBASE_SERVER_CHARSET_QUERY
          SQL query to determine the server charset on Sybase.
private  int sybaseInfo
          Sybase capability mask.
private  boolean tcpNoDelay
          TCP_NODELAY
private  int tdsVersion
          The server protocol version.
private  int textSize
          Connection's current maximum field size limit.
private  int transactionIsolation
          Default transaction isolation level.
private  java.lang.String url
          The orginal connection URL.
private  java.lang.String user
          The database user ID.
private  boolean useUnicode
          Send parameters as unicode.
private  java.lang.String wsid
          Workstation ID.
private  boolean xaEmulation
          True if driver should emulate distributed transactions.
private  int xaState
          Current emulated XA State eg start/end/prepare etc.
private  boolean xaTransaction
          True if running distributed transaction.
private  java.lang.Object xid
          Current XA Transaction ID.
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
private ConnectionJDBC2()
          Default constructor.
(package private) ConnectionJDBC2(java.lang.String url, java.util.Properties info)
          Create a new database connection.
 
Method Summary
(package private)  void addCachedProcedure(java.lang.String key, ConnectionJDBC2.ProcEntry proc)
          Add a stored procedure to the cache.
(package private)  void addStatement(JtdsStatement statement)
          Add a statement object to the list maintained by the connection.
(package private)  void checkLocal(java.lang.String method)
          Check that this connection is in local transaction mode.
(package private)  void checkOpen()
          Check that this connection is still open.
(package private)  void clearSavepoints()
          Releases all savepoints.
 void clearWarnings()
           
 void close()
          Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
 void commit()
           
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int type, int concurrency)
           
 java.sql.Statement createStatement(int type, int concurrency, int holdability)
           
private  java.lang.String determineServerCharset()
          Discovers the server charset for server versions that do not send ENVCHANGE packets on login ack, by executing a DB vendor/version specific query.
(package private)  void enlistConnection(byte[] oleTranID)
          Enlist the current connection in a distributed transaction.
 boolean getAutoCommit()
           
(package private)  int getBatchSize()
          Retrieves the batch size to be used internally.
 java.lang.String getCatalog()
           
protected  java.lang.String getCharset()
          Retrieve the Java charset to use for encoding.
protected  CharsetInfo getCharsetInfo()
          Retrieve the CharsetInfo instance used by this connection.
(package private)  byte[] getCollation()
          Retrieve the SQL Server 2000 default collation.
(package private)  int getDatabaseMajorVersion()
          Retrive the DBMS major version.
(package private)  int getDatabaseMinorVersion()
          Retrive the DBMS minor version.
(package private)  java.lang.String getDatabaseProductName()
          Retrive the DBMS product name.
(package private)  java.lang.String getDatabaseProductVersion()
          Retrive the DBMS proeuct version.
 int getHoldability()
           
(package private)  long getLobBuffer()
          Retrieves the LOB buffer size.
(package private)  int getMaxPrecision()
          Retrieves the maximum decimal precision.
 java.sql.DatabaseMetaData getMetaData()
           
(package private)  Semaphore getMutex()
          Retrieve the connection mutex.
(package private)  int getNetPacketSize()
          Retrieves the network packet size.
(package private)  int getPrepareSql()
          Retrieves the Prepared SQL method.
(package private)  java.lang.String getProcName()
          Retrieve the next unique stored procedure name.
 java.lang.String getRmHost()
          Retrieve the host and port for this connection.
(package private)  int getRowCount()
          Retrieves the current row count on this connection.
(package private)  int getServerType()
          Retrieves the server type.
(package private)  SharedSocket getSocket()
          Retrive the shared socket.
protected  boolean getSybaseInfo(int flag)
          Retrieve the Sybase capability data.
(package private)  int getTdsVersion()
          Retrieve the TDS protocol version.
 int getTextSize()
          Retrieves the current maximum textsize on this connection.
 int getTransactionIsolation()
           
 java.util.Map getTypeMap()
           
(package private)  java.lang.String getURL()
          Retrieve the original connection URL.
 java.sql.SQLWarning getWarnings()
           
(package private)  int getXaState()
          Retrieve the XA state variable.
(package private)  java.lang.Object getXid()
          Get the XA transaction ID when running in emulation mode.
(package private)  boolean isCharsetSpecified()
          Retrieves whether a specific charset was requested on creation.
 boolean isClosed()
           
(package private)  boolean isLastUpdateCount()
          Retrieves the status of the lastUpdateCount flag.
 boolean isReadOnly()
           
protected  boolean isUseUnicode()
          Retrieve the sendParametersAsUnicode flag.
protected  boolean isWideChar()
          Retrieve the multibyte status of the current character set.
(package private)  boolean isXaEmulation()
          Retrieve the XA Emulation flag.
private  void loadCharset(CharsetInfo ci, java.lang.String ref)
          Load the Java charset to match the server character set.
private  void loadCharset(java.lang.String charset)
          Load the Java charset to match the server character set.
 java.lang.String nativeSQL(java.lang.String sql)
           
(package private)  void notImplemented(java.lang.String method)
          Report that user tried to call a method which has not been implemented.
private  int parseIntegerProperty(java.util.Properties info, java.lang.String key)
          Parse a string property value into an integer value.
private  long parseLongProperty(java.util.Properties info, java.lang.String key)
          Parse a string property value into a long value.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int type, int concurrency)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int type, int concurrency, int holdability)
           
(package private)  java.lang.String prepareSQL(JtdsPreparedStatement pstmt, java.lang.String sql, ParamInfo[] params, boolean returnKeys)
          Try to convert the SQL statement into a stored procedure.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int type, int concurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int type, int concurrency, int holdability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
           
 void releaseSavepoint(java.sql.Savepoint savepoint)
           
(package private)  void removeCachedProcedure(java.lang.String key)
          Remove a stored procedure from the cache.
(package private)  void removeStatement(JtdsStatement statement)
          Remove a statement object from the list maintained by the connection and clean up the statement cache if necessary.
 void rollback()
           
 void rollback(java.sql.Savepoint savepoint)
           
(package private)  byte[][] sendXaPacket(int[] args, byte[] data)
          Invoke the xp_jtdsxa extended stored procedure on the server.
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
(package private)  void setClosed()
          Used to force the closed status on the statement if an IO error has occurred.
(package private)  void setCollation(byte[] collation)
          Set the default collation for this connection.
protected  void setDatabase(java.lang.String newDb, java.lang.String oldDb)
          Called by the protcol to change the current database context.
protected  void setDBServerInfo(java.lang.String databaseProductName, int databaseMajorVersion, int databaseMinorVersion, int buildNumber)
          Update the connection instance with information about the server.
 void setHoldability(int holdability)
           
(package private)  void setNetPacketSize(int size)
          Sets the network packet size.
 void setReadOnly(boolean readOnly)
           
(package private)  void setRowCount(int count)
          Sets the current row count on this connection.
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String name)
           
protected  void setServerCharset(java.lang.String charset)
          Called by the protocol to change the current character set.
protected  void setSybaseInfo(int mask)
          Set the Sybase capability data.
 void setTextSize(int textSize)
          Sets the current maximum textsize on this connection.
 void setTransactionIsolation(int level)
           
 void setTypeMap(java.util.Map map)
           
(package private)  void setXaState(int value)
          Set the XA state variable.
(package private)  void setXid(java.lang.Object xid)
          Set the XA transaction ID when running in emulation mode.
protected  void unpackProperties(java.util.Properties info)
          Transfers the properties to the local instance variables.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SYBASE_SERVER_CHARSET_QUERY

private static final java.lang.String SYBASE_SERVER_CHARSET_QUERY
SQL query to determine the server charset on Sybase.

SQL_SERVER_65_CHARSET_QUERY

private static final java.lang.String SQL_SERVER_65_CHARSET_QUERY
SQL query to determine the server charset on MS SQL Server 6.5.

SYBASE_INITIAL_SQL

private java.lang.String SYBASE_INITIAL_SQL
Sybase initial connection string.

SQL_SERVER_INITIAL_SQL

private java.lang.String SQL_SERVER_INITIAL_SQL
SQL Server initial connection string. Also contains a SELECT

url

private java.lang.String url
The orginal connection URL.

serverName

private java.lang.String serverName
The server host name.

portNumber

private int portNumber
The server port number.

serverType

private int serverType
The make of SQL Server (sybase/microsoft).

instanceName

private java.lang.String instanceName
The SQL Server instance.

databaseName

private java.lang.String databaseName
The requested database name.

currentDatabase

private java.lang.String currentDatabase
The current database name.

domainName

private java.lang.String domainName
The Windows Domain name.

user

private java.lang.String user
The database user ID.

password

private java.lang.String password
The user password.

serverCharset

private java.lang.String serverCharset
The server character set.

appName

private java.lang.String appName
The application name.

progName

private java.lang.String progName
The program name.

wsid

private java.lang.String wsid
Workstation ID.

language

private java.lang.String language
The server message language.

macAddress

private java.lang.String macAddress
The client MAC Address.

tdsVersion

private int tdsVersion
The server protocol version.

socket

private SharedSocket socket
The network TCP/IP socket.

baseTds

private TdsCore baseTds
The cored TDS protocol object.

netPacketSize

private int netPacketSize
The initial network packet size.

packetSize

private int packetSize
User requested packet size.

collation

private byte[] collation
SQL Server 2000 collation.

charsetSpecified

private boolean charsetSpecified
True if user specifies an explicit charset.

databaseProductName

private java.lang.String databaseProductName
The database product name eg SQL SERVER.

databaseProductVersion

private java.lang.String databaseProductVersion
The product version eg 11.92.

databaseMajorVersion

private int databaseMajorVersion
The major version number eg 11.

databaseMinorVersion

private int databaseMinorVersion
The minor version number eg 92.

closed

private boolean closed
True if this connection is closed.

readOnly

private boolean readOnly
True if this connection is read only.

statements

private java.util.ArrayList statements
List of statements associated with this connection.

transactionIsolation

private int transactionIsolation
Default transaction isolation level.

autoCommit

private boolean autoCommit
Default auto commit state.

messages

private SQLDiagnostic messages
Diagnostc messages for this connection.

rowCount

private int rowCount
Connection's current rowcount limit.

textSize

private int textSize
Connection's current maximum field size limit.

maxPrecision

private int maxPrecision
Maximum decimal precision.

spSequenceNo

private int spSequenceNo
Stored procedure unique ID number.

procInTran

private java.util.ArrayList procInTran
Procedures in this transaction.

charsetInfo

private CharsetInfo charsetInfo
Java charset for encoding.

prepareSql

private int prepareSql
Method for preparing SQL used in Prepared Statements.

lobBuffer

private long lobBuffer
The amount of LOB data to buffer in memory.

maxStatements

private int maxStatements
The maximum number of statements to keep open.

statementCache

private StatementCache statementCache
Statement cache.

useUnicode

private boolean useUnicode
Send parameters as unicode.

namedPipe

private boolean namedPipe
Use named pipe IPC instead of TCP/IP sockets.

lastUpdateCount

private boolean lastUpdateCount
Only return the last update count.

tcpNoDelay

private boolean tcpNoDelay
TCP_NODELAY

loginTimeout

private int loginTimeout
Login timeout value in seconds or 0.

sybaseInfo

private int sybaseInfo
Sybase capability mask.

xaTransaction

private boolean xaTransaction
True if running distributed transaction.

xaState

private int xaState
Current emulated XA State eg start/end/prepare etc.

xid

private java.lang.Object xid
Current XA Transaction ID.

xaEmulation

private boolean xaEmulation
True if driver should emulate distributed transactions.

mutex

private Semaphore mutex
Mutual exclusion lock to control access to connection.

ssl

private java.lang.String ssl
SSL setting.

batchSize

private int batchSize
The maximum size of a batch.
Constructor Detail

ConnectionJDBC2

private ConnectionJDBC2()
Default constructor.

Used for testing.


ConnectionJDBC2

ConnectionJDBC2(java.lang.String url,
                java.util.Properties info)
          throws java.sql.SQLException
Create a new database connection.
Parameters:
url - The connection URL starting jdbc:jtds:.
info - The additional connection properties.
Throws:
java.sql.SQLException -  
Method Detail

getSocket

SharedSocket getSocket()
Retrive the shared socket.
Returns:
The SharedSocket object.

getTdsVersion

int getTdsVersion()
Retrieve the TDS protocol version.
Returns:
The TDS version as an int.

getProcName

java.lang.String getProcName()
Retrieve the next unique stored procedure name.

Notes:

  1. Some versions of Sybase require an id with a length of <= 10.
  2. The format of this name works for sybase and Microsoft and allows for 16M names per session.
  3. The leading '#jtds' indicates this is a temporary procedure and the '#' is removed by the lower level TDS5 routines.
Returns:
The sp name as a String.

prepareSQL

java.lang.String prepareSQL(JtdsPreparedStatement pstmt,
                            java.lang.String sql,
                            ParamInfo[] params,
                            boolean returnKeys)
                      throws java.sql.SQLException
Try to convert the SQL statement into a stored procedure.

Synchronized because it accesses the procedure cache and the baseTds, but the method call also needs to made in a synchronized (connection) block together with the execution (if the prepared statement is actually executed) to ensure the transaction isn't rolled back between this method call and the actual execution.

Parameters:
sql - the SQL statement to prepare
params - the parameters
Returns:
the SQL procedure name as a String or null if the SQL cannot be prepared

addCachedProcedure

void addCachedProcedure(java.lang.String key,
                        ConnectionJDBC2.ProcEntry proc)
Add a stored procedure to the cache.

Not explicitly synchronized because it's only called by synchronized methods.

Parameters:
key - The signature of the procedure to cache.
proc - The stored procedure descriptor.

removeCachedProcedure

void removeCachedProcedure(java.lang.String key)
Remove a stored procedure from the cache.

Not explicitly synchronized because it's only called by synchronized methods.

Parameters:
key - The signature of the procedure to remove from the cache.

getServerType

int getServerType()
Retrieves the server type.
Returns:
the server type as an int where 1 == SQLSERVER and 2 == SYBASE.

setNetPacketSize

void setNetPacketSize(int size)
Sets the network packet size.
Parameters:
size - the new packet size

getNetPacketSize

int getNetPacketSize()
Retrieves the network packet size.
Returns:
the packet size as an int

getRowCount

int getRowCount()
Retrieves the current row count on this connection.
Returns:
the row count as an int

setRowCount

void setRowCount(int count)
Sets the current row count on this connection.
Parameters:
count - the new row count

getTextSize

public int getTextSize()
Retrieves the current maximum textsize on this connection.
Returns:
the maximum textsize as an int

setTextSize

public void setTextSize(int textSize)
Sets the current maximum textsize on this connection.
Parameters:
textSize - the new maximum textsize

isLastUpdateCount

boolean isLastUpdateCount()
Retrieves the status of the lastUpdateCount flag.
Returns:
the lastUpdateCount flag as a boolean

getMaxPrecision

int getMaxPrecision()
Retrieves the maximum decimal precision.
Returns:
the precision as an int

getLobBuffer

long getLobBuffer()
Retrieves the LOB buffer size.
Returns:
the LOB buffer size as a long

getPrepareSql

int getPrepareSql()
Retrieves the Prepared SQL method.
Returns:
the Prepared SQL method

getBatchSize

int getBatchSize()
Retrieves the batch size to be used internally.
Returns:
the batch size as an int

unpackProperties

protected void unpackProperties(java.util.Properties info)
                         throws java.sql.SQLException
Transfers the properties to the local instance variables.
Parameters:
info - The connection properties Object.
Throws:
java.sql.SQLException - If an invalid property value is found.

parseIntegerProperty

private int parseIntegerProperty(java.util.Properties info,
                                 java.lang.String key)
                          throws java.sql.SQLException
Parse a string property value into an integer value.
Parameters:
info - The connection properties object.
key - The message key used to retrieve the property name.
Returns:
The integer value of the string property value.
Throws:
java.sql.SQLException - If the property value can't be parsed.

parseLongProperty

private long parseLongProperty(java.util.Properties info,
                               java.lang.String key)
                        throws java.sql.SQLException
Parse a string property value into a long value.
Parameters:
info - The connection properties object.
key - The message key used to retrieve the property name.
Returns:
The long value of the string property value.
Throws:
java.sql.SQLException - If the property value can't be parsed.

getCharset

protected java.lang.String getCharset()
Retrieve the Java charset to use for encoding.
Returns:
the Charset name as a String

isWideChar

protected boolean isWideChar()
Retrieve the multibyte status of the current character set.
Returns:
boolean true if a multi byte character set

getCharsetInfo

protected CharsetInfo getCharsetInfo()
Retrieve the CharsetInfo instance used by this connection.
Returns:
the default CharsetInfo for this connection

isUseUnicode

protected boolean isUseUnicode()
Retrieve the sendParametersAsUnicode flag.
Returns:
boolean true if parameters should be sent as unicode.

getSybaseInfo

protected boolean getSybaseInfo(int flag)
Retrieve the Sybase capability data.
Returns:
Capability bit mask as an int.

setSybaseInfo

protected void setSybaseInfo(int mask)
Set the Sybase capability data.
Parameters:
mask - The capability bit mask.

setServerCharset

protected void setServerCharset(java.lang.String charset)
                         throws java.sql.SQLException
Called by the protocol to change the current character set.
Parameters:
charset - the server character set name

loadCharset

private void loadCharset(java.lang.String charset)
                  throws java.sql.SQLException
Load the Java charset to match the server character set.
Parameters:
charset - the server character set

loadCharset

private void loadCharset(CharsetInfo ci,
                         java.lang.String ref)
                  throws java.sql.SQLException
Load the Java charset to match the server character set.
Parameters:
ci - the CharsetInfo to load

determineServerCharset

private java.lang.String determineServerCharset()
                                         throws java.sql.SQLException
Discovers the server charset for server versions that do not send ENVCHANGE packets on login ack, by executing a DB vendor/version specific query.

Will throw an SQLException if used on SQL Server 7.0 or 2000; the idea is that the charset should already be determined from ENVCHANGE packets for these DB servers.

Should only be called from the constructor.

Returns:
the default server charset
Throws:
java.sql.SQLException - if an error condition occurs

setCollation

void setCollation(byte[] collation)
            throws java.sql.SQLException
Set the default collation for this connection.

Set by a SQL Server 2000 environment change packet. The collation consists of the following fields:

  • bits 0-19 - The locale eg 0x0409 for US English which maps to code page 1252 (Latin1_General).
  • bits 20-31 - Reserved.
  • bits 32-39 - Sort order (csid from syscharsets)
If the sort order is non-zero it determines the character set, otherwise the character set is determined by the locale id.
Parameters:
collation - The new collation.

getCollation

byte[] getCollation()
Retrieve the SQL Server 2000 default collation.
Returns:
The collation as a byte[5].

isCharsetSpecified

boolean isCharsetSpecified()
Retrieves whether a specific charset was requested on creation. If this is the case, all character data should be encoded/decoded using that charset.

setDatabase

protected void setDatabase(java.lang.String newDb,
                           java.lang.String oldDb)
                    throws java.sql.SQLException
Called by the protcol to change the current database context.
Parameters:
newDb - The new database selected on the server.
oldDb - The old database as known by the server.
Throws:
java.sql.SQLException -  

setDBServerInfo

protected void setDBServerInfo(java.lang.String databaseProductName,
                               int databaseMajorVersion,
                               int databaseMinorVersion,
                               int buildNumber)
Update the connection instance with information about the server.
Parameters:
databaseProductName - The server name eg SQL Server.
databaseMajorVersion - The major version eg 11
databaseMinorVersion - The minor version eg 92
buildNumber - The server build number.

removeStatement

void removeStatement(JtdsStatement statement)
               throws java.sql.SQLException
Remove a statement object from the list maintained by the connection and clean up the statement cache if necessary.

Synchronized because it accesses the statement list, the statement cache and the baseTds.

Parameters:
statement - the statement to remove

addStatement

void addStatement(JtdsStatement statement)
Add a statement object to the list maintained by the connection.

WeakReferences are used so that statements can still be closed and garbage collected even if not explicitly closed by the connection.

Parameters:
statement - The statement to add.

checkOpen

void checkOpen()
         throws java.sql.SQLException
Check that this connection is still open.
Throws:
java.sql.SQLException - if connection closed.

checkLocal

void checkLocal(java.lang.String method)
          throws java.sql.SQLException
Check that this connection is in local transaction mode.
Parameters:
method - The method name being tested.
Throws:
java.sql.SQLException - if in XA distributed transaction mode

notImplemented

void notImplemented(java.lang.String method)
              throws java.sql.SQLException
Report that user tried to call a method which has not been implemented.
Parameters:
method - The method name to report in the error message.
Throws:
java.sql.SQLException -  

getDatabaseMajorVersion

int getDatabaseMajorVersion()
Retrive the DBMS major version.
Returns:
The version as an int.

getDatabaseMinorVersion

int getDatabaseMinorVersion()
Retrive the DBMS minor version.
Returns:
The version as an int.

getDatabaseProductName

java.lang.String getDatabaseProductName()
Retrive the DBMS product name.
Returns:
The name as a String.

getDatabaseProductVersion

java.lang.String getDatabaseProductVersion()
Retrive the DBMS proeuct version.
Returns:
The version as a String.

getURL

java.lang.String getURL()
Retrieve the original connection URL.
Returns:
The connection url as a String.

getRmHost

public java.lang.String getRmHost()
Retrieve the host and port for this connection.

Used to identify same resource manager in XA transactions.

Returns:
the hostname and port as a String.

setClosed

void setClosed()
Used to force the closed status on the statement if an IO error has occurred.

sendXaPacket

byte[][] sendXaPacket(int[] args,
                      byte[] data)
                throws java.sql.SQLException
Invoke the xp_jtdsxa extended stored procedure on the server.

Synchronized because it accesses the baseTds.

Parameters:
args - the arguments eg cmd, rmid, flags etc.
data - option byte data eg open string xid etc.
Returns:
optional byte data eg OLE cookie.
Throws:
java.sql.SQLException - if an error condition occurs

enlistConnection

void enlistConnection(byte[] oleTranID)
                throws java.sql.SQLException
Enlist the current connection in a distributed transaction.
Parameters:
oleTranID - the OLE transaction cookie or null to delist
Throws:
java.sql.SQLException - if an error condition occurs

setXid

void setXid(java.lang.Object xid)
Set the XA transaction ID when running in emulation mode.
Parameters:
xid - the XA Transaction ID

getXid

java.lang.Object getXid()
Get the XA transaction ID when running in emulation mode.
Returns:
the transaction ID as an Object

setXaState

void setXaState(int value)
Set the XA state variable.
Parameters:
value - the XA state value

getXaState

int getXaState()
Retrieve the XA state variable.
Returns:
the xa state variable as an int

isXaEmulation

boolean isXaEmulation()
Retrieve the XA Emulation flag.
Returns:
True if in XA emulation mode.

getMutex

Semaphore getMutex()
Retrieve the connection mutex.
Returns:
the mutex object as a Semaphore

getHoldability

public int getHoldability()
                   throws java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection

close

public void close()
           throws java.sql.SQLException
Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.

Calling the method close on a Connection object that is already closed is a no-op.

Note: A Connection object is automatically closed when it is garbage collected. Certain fatal errors also close a Connection object.

Synchronized because it accesses the statement list and the baseTds.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - if a database access error occurs

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection

setHoldability

public void setHoldability(int holdability)
                    throws java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection

createStatement

public java.sql.Statement createStatement(int type,
                                          int concurrency)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection

createStatement

public java.sql.Statement createStatement(int type,
                                          int concurrency,
                                          int holdability)
                                   throws java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int type,
                                              int concurrency)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int type,
                                              int concurrency,
                                              int holdability)
                                       throws java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int autoGeneratedKeys)
                                            throws java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int type,
                                                   int concurrency)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int type,
                                                   int concurrency,
                                                   int holdability)
                                            throws java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] columnIndexes)
                                            throws java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String name)
                                throws java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] columnNames)
                                            throws java.sql.SQLException

clearSavepoints

void clearSavepoints()
Releases all savepoints. Used internally when committing or rolling back a transaction.


Generated on April 15 2005