Class JtdsConnection
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
Implementation notes:
- Environment setting code carried over from old jTDS otherwise generally a new implementation of Connection.
- Connection properties and SQLException text messages are loaded from a properties file.
- Character set choices are also loaded from a resource file and the original Encoder class has gone.
- Prepared SQL statements are converted to procedures in the prepareSQL method.
- Use of Stored procedures is optional and controlled via connection property.
- 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: JtdsConnection.java,v 1.119.2.14 2010-05-17 10:27:00 ickzon Exp $
- Author:
- Mike Hutchinson, Alin Sinpalean
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe application name.private booleanDefault auto commit state.private final TdsCoreThe cored TDS protocol object.private intThe maximum size of a batch.private StringThe local address to bind to when connecting to a database via TCP/IP.private FileThe directory to buffer data toprivate intThe global buffer memory limit for all connections (in kilobytes).private intThe minimum number of packets per statement to buffer to memory.private TdsCoreA cachedTdsCoreinstance to reuse on new statements.private CharsetInfoJava charset for encoding.private booleanTrue if user specifies an explicit charset.private booleanTrue if this connection is closed.private byte[]SQL Server 2000 collation.private static int[]the number of currently open connectionsprivate StringThe current database name.private intCursor unique ID number.private intThe major version number eg 11.private intThe minor version number eg 92.private StringThe requested database name.private StringThe database product name eg SQL SERVER.private StringThe product version eg 11.92.private StringThe Windows Domain name.private StringThe SQL Server instance.private StringThe server message language.private booleanOnly return the last update count.private longThe amount of LOB data to buffer in memory.private intLogin timeout value in seconds or 0.private StringThe client MAC Address.private intMaximum decimal precision.private intThe maximum number of statements to keep open.private final SQLDiagnosticDiagnostc messages for this connection.private final SemaphoreMutual exclusion lock to control access to connection.private booleanUse named pipe IPC instead of TCP/IP sockets.private intThe initial network packet size.private intUser requested packet size.private StringThe user password.private intThe server port number.private intMethod for preparing SQL used in Prepared Statements.private static IntegerThe process ID to report to a server when connecting.private final ArrayListProcedures in this transaction.private StringThe program name.private booleanTrue if this connection is read only.private intConnection's current rowcount limit.private intCounter for generating unique savepoint identifiersprivate MapMaps each savepoint to a list of temp procedures created since the savepointprivate ArrayListThe list of savepoints.private StringThe server character set.private StringThe server host name.private intThe make of SQL Server (sybase/microsoft).private final SharedSocketThe network TCP/IP socket.private booleanTrue to enable socket keep alive.private intSocket timeout value in seconds or 0.private intStored procedure unique ID number.private static final StringSQL query to determine the server charset on MS SQL Server 6.5.private static final StringSQL Server initial connection string.private StringSSL setting.private StatementCacheStatement cache.private final ArrayListList of statements associated with this connection.private static final StringSybase initial connection string.private static final StringSQL query to determine the server charset on Sybase.private intSybase capability mask.private booleanTCP_NODELAYprivate intThe server protocol version.private intConnection's current maximum field size limit.static final intSQL Server custom transaction isolation level.private intDefault transaction isolation level.private final StringThe orginal connection URL.private booleanUse fast forward cursors for forward only result sets.private booleanForce use of jCIFS library on Windows when connecting via named pipes.private booleanForce Kerberos authenticationprivate booleanMap large types (IMAGE and TEXT/NTEXT) to LOBs by default.private booleanUse metadata cache for prepared statements.private booleanWhen doing NTLM authentication, send NTLMv2 response rather than regular responseprivate StringThe database user ID.private booleanSend parameters as unicode.private StringWorkstation ID.private booleanTrue if driver should emulate distributed transactions.private intCurrent emulated XA State eg start/end/prepare etc.private booleanTrue if running distributed transaction.private ObjectCurrent 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
ConstructorsModifierConstructorDescriptionprivateDefault constructor.(package private)JtdsConnection(String url, Properties info) Create a new database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid(package private) voidaddCachedProcedure(String key) Add a stored procedure to the savepoint cache.(package private) voidaddCachedProcedure(String key, ProcEntry proc) Add a stored procedure to the cache.(package private) voidaddStatement(JtdsStatement statement) Adds a statement object to the list maintained by the connection.(package private) voidcheckLocal(String method) Checks that this connection is in local transaction mode.(package private) voidChecks that the connection is still open.private voidReleases all savepoints.voidvoidclose()Releases thisConnectionobject's database and JDBC resources immediately instead of waiting for them to be automatically released.voidcommit()createArrayOf(String typeName, Object[] elements) private SharedSocketcreateNamedPipe(JtdsConnection connection) Creates aSharedSocketobject representing a connection to a named pipe.createStatement(int type, int concurrency) createStatement(int type, int concurrency, int holdability) createStruct(String typeName, Object[] attributes) private StringDiscovers the server charset for server versions that do not sendENVCHANGEpackets on login ack, by executing a DB vendor/version specific query.(package private) voidenlistConnection(byte[] oleTranID) Enlists the current connection in a distributed transaction.protected voidfinalize()Ensure all resources are released.(package private) StringRetrieves the application name for this connection.boolean(package private) intRetrieves the batch size to be used internally.(package private) StringRetrieves the bind address for this connection.(package private) FileReturns the directory where data should be buffered to.(package private) intRetrieves the maximum amount of memory in Kb to buffer for all connections.(package private) intRetrieves the minimum number of packets to buffer perStatementfor this connection.(package private) TdsCoreRetrieves the cachedTdsCoreornullif nothing is cached and resets the cache (sets it tonull).protected StringRetrieve the Java charset to use for encoding.protected CharsetInfoRetrieve theCharsetInfoinstance used by this connection.getClientInfo(String name) (package private) byte[]Retrieve the SQL Server 2000 default collation.(package private) StringRetrieves the next unique cursor name.intRetrieves the DBMS major version.intRetrieves the DBMS minor version.(package private) StringRetrieves the database name for this connection.(package private) StringRetrieves the DBMS product name.(package private) StringRetrieves the DBMS product version.(package private) StringRetrieves the domain name for this connection.int(package private) StringRetrieves the instance name for this connection.(package private) booleanRetrieves the status of the lastUpdateCount flag.(package private) longRetrieves the LOB buffer size.(package private) intRetrieves the login timeout for this connection.(package private) StringRetrieves the MAC (ethernet) address for this connection.(package private) intRetrieves the maximum decimal precision.(package private) intRetrieves the maximum statement cache size.(package private) SemaphoregetMutex()Retrieves the connection mutex and acquires an exclusive lock on the network connection.(package private) booleanRetrieves the named pipe setting for this connection.(package private) intRetrieves the network packet size.intprivate intReturns the next savepoint identifier.(package private) intRetrieves the packet size for this connection.(package private) StringRetrieves the password for this connection.(package private) intRetrieves the port number for this connection.(package private) intRetrieves the Prepared SQL method.(package private) intRetrieves the process ID to send to a server when a connection is established.(package private) StringRetrieves the next unique stored procedure name.(package private) StringRetrieves the program name for this connection.Retrieves the host and port for this connection.(package private) intRetrieves the current row count on this connection.(package private) StringRetrieves the server name for this connection.intRetrieves the server type.(package private) SharedSocketRetrive the shared socket.(package private) booleanRetrieves whether to enable socket keep alive.(package private) intRetrieves the socket timeout for this connection.protected booleangetSybaseInfo(int flag) Retrieve the Sybase capability data.(package private) booleanRetrieves the tcpNoDelay setting for this connection.(package private) intRetrieve the TDS protocol version.intRetrieves the current maximum textsize on this connection.int(package private) StringgetURL()Retrieves the original connection URL.(package private) booleanIndicates whether fast forward only cursors should be used for forward only result sets.(package private) booleanRetrieves the useJCIFS setting for this connection.(package private) booleanReturn whether to use Kerberos authentication for MS SQL Server.(package private) booleanIndicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types orStringandbyte[]respectively.(package private) booleanRetrieves the boolean indicating whether metadata caching is enabled.(package private) booleanIndicates whether, when doing Windows authentication to an MS SQL server, NTLMv2 should be used.(package private) StringgetUser()Retrieves the user for this connection.protected booleanRetrieve the sendParametersAsUnicode flag.(package private) StringgetWsid()Retrieves the workstation ID (WSID) for this connection.(package private) intRetrieves the XA state variable.(package private) ObjectgetXid()Gets the XA transaction ID when running in emulation mode.(package private) booleanRetrieves whether a specific charset was requested on creation.booleanisClosed()booleanbooleanisValid(int timeout) protected booleanRetrieve the multibyte status of the current character set.booleanisWrapperFor(Class arg0) (package private) booleanRetrieves the XA Emulation flag.private voidloadCharset(String charset) Load the Java charset to match the server character set.private voidloadCharset(CharsetInfo ci, String ref) Load the Java charset to match the server character set.(package private) static voidnotImplemented(String method) Reports that user tried to call a method which has not been implemented.private static booleanparseBooleanProperty(Properties info, String key) Parse a string property value into an boolean value.private static intparseIntegerProperty(Properties info, String key) Parse a string property value into an integer value.private static longparseLongProperty(Properties info, String key) Parse a string property value into a long value.prepareCall(String sql) prepareCall(String sql, int type, int concurrency) prepareCall(String sql, int type, int concurrency, int holdability) (package private) StringprepareSQL(JtdsPreparedStatement pstmt, String sql, ParamInfo[] params, boolean returnKeys, boolean cursorNeeded) Try to convert the SQL statement into a statement prepare.prepareStatement(String sql) prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) prepareStatement(String sql, int type, int concurrency) prepareStatement(String sql, int type, int concurrency, int holdability) prepareStatement(String sql, String[] columnNames) voidreleaseSavepoint(Savepoint savepoint) (package private) voidreleaseTds(TdsCore tds) Releases (either closes or caches) aTdsCore.(package private) voidRemove a stored procedure from the cache.(package private) voidremoveStatement(JtdsStatement statement) Removes a statement object from the list maintained by the connection and cleans up the statement cache if necessary.voidrollback()void(package private) byte[][]sendXaPacket(int[] args, byte[] data) Invokes thexp_jtdsxaextended stored procedure on the server.voidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) voidsetClientInfo(Properties properties) (package private) voidForces the closed status on the statement if an I/O error has occurred.(package private) voidsetCollation(byte[] collation) Set the default collation for this connection.protected voidsetDatabase(String newDb, String oldDb) Called by the protcol to change the current database context.protected voidsetDBServerInfo(String databaseProductName, int databaseMajorVersion, int databaseMinorVersion, int buildNumber) Update the connection instance with information about the server.voidsetHoldability(int holdability) (package private) voidsetNetPacketSize(int size) Sets the network packet size.voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) (package private) voidsetRowCount(int count) Sets the current row count on this connection.setSavepoint(String name) private voidsetSavepoint(SavepointImpl savepoint) Add a savepoint to the list maintained by this connection.voidprotected voidsetServerCharset(String charset) Called by the protocol to change the current character set.protected voidsetSybaseInfo(int mask) Set the Sybase capability data.voidsetTextSize(int textSize) Sets the current maximum textsize on this connection.voidsetTransactionIsolation(int level) voidsetTypeMap(Map map) (package private) voidsetXaState(int value) Sets the XA state variable.(package private) voidSets the XA transaction ID when running in emulation mode.protected voidunpackProperties(Properties info) Transfers the properties to the local instance variables.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
SYBASE_SERVER_CHARSET_QUERY
SQL query to determine the server charset on Sybase.- See Also:
-
SQL_SERVER_65_CHARSET_QUERY
SQL query to determine the server charset on MS SQL Server 6.5.- See Also:
-
SYBASE_INITIAL_SQL
Sybase initial connection string.- See Also:
-
SQL_SERVER_INITIAL_SQL
SQL Server initial connection string. Also contains aSELECT @@MAX_PRECISIONquery to retrieve the maximum precision for DECIMAL/NUMERIC data.- See Also:
-
TRANSACTION_SNAPSHOT
public static final int TRANSACTION_SNAPSHOTSQL Server custom transaction isolation level.- See Also:
-
url
The orginal connection URL. -
serverName
The server host name. -
portNumber
private int portNumberThe server port number. -
serverType
private int serverTypeThe make of SQL Server (sybase/microsoft). -
instanceName
The SQL Server instance. -
databaseName
The requested database name. -
currentDatabase
The current database name. -
domainName
The Windows Domain name. -
user
The database user ID. -
password
The user password. -
serverCharset
The server character set. -
appName
The application name. -
progName
The program name. -
wsid
Workstation ID. -
language
The server message language. -
macAddress
The client MAC Address. -
tdsVersion
private int tdsVersionThe server protocol version. -
socket
The network TCP/IP socket. -
baseTds
The cored TDS protocol object. -
netPacketSize
private int netPacketSizeThe initial network packet size. -
packetSize
private int packetSizeUser requested packet size. -
collation
private byte[] collationSQL Server 2000 collation. -
charsetSpecified
private boolean charsetSpecifiedTrue if user specifies an explicit charset. -
databaseProductName
The database product name eg SQL SERVER. -
databaseProductVersion
The product version eg 11.92. -
databaseMajorVersion
private int databaseMajorVersionThe major version number eg 11. -
databaseMinorVersion
private int databaseMinorVersionThe minor version number eg 92. -
closed
private boolean closedTrue if this connection is closed. -
readOnly
private boolean readOnlyTrue if this connection is read only. -
statements
List of statements associated with this connection. -
transactionIsolation
private int transactionIsolationDefault transaction isolation level. -
autoCommit
private boolean autoCommitDefault auto commit state. -
messages
Diagnostc messages for this connection. -
rowCount
private int rowCountConnection's current rowcount limit. -
textSize
private int textSizeConnection's current maximum field size limit. -
maxPrecision
private int maxPrecisionMaximum decimal precision. -
spSequenceNo
private int spSequenceNoStored procedure unique ID number. -
cursorSequenceNo
private int cursorSequenceNoCursor unique ID number. -
procInTran
Procedures in this transaction. -
charsetInfo
Java charset for encoding. -
prepareSql
private int prepareSqlMethod for preparing SQL used in Prepared Statements. -
lobBuffer
private long lobBufferThe amount of LOB data to buffer in memory. -
maxStatements
private int maxStatementsThe maximum number of statements to keep open. -
statementCache
Statement cache. -
useUnicode
private boolean useUnicodeSend parameters as unicode. -
namedPipe
private boolean namedPipeUse named pipe IPC instead of TCP/IP sockets. -
lastUpdateCount
private boolean lastUpdateCountOnly return the last update count. -
tcpNoDelay
private boolean tcpNoDelayTCP_NODELAY -
loginTimeout
private int loginTimeoutLogin timeout value in seconds or 0. -
sybaseInfo
private int sybaseInfoSybase capability mask. -
xaTransaction
private boolean xaTransactionTrue if running distributed transaction. -
xaState
private int xaStateCurrent emulated XA State eg start/end/prepare etc. -
xid
Current XA Transaction ID. -
xaEmulation
private boolean xaEmulationTrue if driver should emulate distributed transactions. -
mutex
Mutual exclusion lock to control access to connection. -
socketTimeout
private int socketTimeoutSocket timeout value in seconds or 0. -
socketKeepAlive
private boolean socketKeepAliveTrue to enable socket keep alive. -
processId
The process ID to report to a server when connecting. -
ssl
SSL setting. -
batchSize
private int batchSizeThe maximum size of a batch. -
useMetadataCache
private boolean useMetadataCacheUse metadata cache for prepared statements. -
useCursors
private boolean useCursorsUse fast forward cursors for forward only result sets. -
bufferDir
The directory to buffer data to -
bufferMaxMemory
private int bufferMaxMemoryThe global buffer memory limit for all connections (in kilobytes). -
bufferMinPackets
private int bufferMinPacketsThe minimum number of packets per statement to buffer to memory. -
useLOBs
private boolean useLOBsMap large types (IMAGE and TEXT/NTEXT) to LOBs by default. -
cachedTds
A cachedTdsCoreinstance to reuse on new statements. -
bindAddress
The local address to bind to when connecting to a database via TCP/IP. -
useJCIFS
private boolean useJCIFSForce use of jCIFS library on Windows when connecting via named pipes. -
useNTLMv2
private boolean useNTLMv2When doing NTLM authentication, send NTLMv2 response rather than regular response -
useKerberos
private boolean useKerberosForce Kerberos authentication -
connections
private static int[] connectionsthe number of currently open connections -
savepoints
The list of savepoints. -
savepointProcInTran
Maps each savepoint to a list of temp procedures created since the savepoint -
savepointId
private int savepointIdCounter for generating unique savepoint identifiers
-
-
Constructor Details
-
JtdsConnection
private JtdsConnection()Default constructor. Used for testing. -
JtdsConnection
JtdsConnection(String url, Properties info) throws SQLException Create a new database connection.- Parameters:
url- The connection URL starting jdbc:jtds:.info- The additional connection properties.- Throws:
SQLException
-
-
Method Details
-
finalize
Ensure all resources are released. -
createNamedPipe
Creates aSharedSocketobject representing a connection to a named pipe. If theos.namesystem property starts with "Windows" (case-insensitive) and theuseJCIFSparameter isfalse, aSharedLocalNamedPipeobject is created. Else aSharedNamedPipeis created which uses jCIFS to provide a pure-Java implementation of Windows named pipes.This method will retry for
loginTimeoutseconds to create a named pipe if anIOExceptioncontinues to be thrown stating, "All pipe instances are busy". IfloginTimeoutis set to zero (e.g., not set), a default of 20 seconds will be used.- Parameters:
connection- the connection object- Returns:
- an object representing the named pipe connection
- Throws:
IOException- on error; if anIOExceptionis thrown with a message stating "All pipe instances are busy", then the method timed out afterloginTimeoutmilliseconds attempting to create a named pipe.
-
getSocket
SharedSocket getSocket()Retrive the shared socket.- Returns:
- The
SharedSocketobject.
-
getTdsVersion
int getTdsVersion()Retrieve the TDS protocol version.- Returns:
- The TDS version as an
int.
-
getProcName
String getProcName()Retrieves the next unique stored procedure name.Notes:
- Some versions of Sybase require an id with a length of <= 10.
- The format of this name works for sybase and Microsoft and allows for 16M names per session.
- The leading '#jtds' indicates this is a temporary procedure and the '#' is removed by the lower level TDS5 routines.
prepareSQL(net.sourceforge.jtds.jdbc.JtdsPreparedStatement, java.lang.String, net.sourceforge.jtds.jdbc.ParamInfo[], boolean, boolean)method.- Returns:
- the next temporary SP name as a
String
-
getCursorName
String getCursorName()Retrieves the next unique cursor name.- Returns:
- the next cursor name as a
String
-
prepareSQL
String prepareSQL(JtdsPreparedStatement pstmt, String sql, ParamInfo[] params, boolean returnKeys, boolean cursorNeeded) throws SQLException Try to convert the SQL statement into a statement prepare.Synchronized because it accesses the procedure cache and the
baseTds, but the method call also needs to made in asynchronized (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:
pstmt- the target prepared statementsql- the SQL statement to prepareparams- the parametersreturnKeys- indicates whether the statement will return generated keyscursorNeeded- indicates whether a cursor prepare is needed- Returns:
- the SQL procedure name as a
Stringor null if the SQL cannot be prepared - Throws:
SQLException
-
addCachedProcedure
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
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.
-
getMaxStatements
int getMaxStatements()Retrieves the maximum statement cache size.- Returns:
- the maximum statement cache size
-
getServerType
public int getServerType()Retrieves the server type.- Returns:
- the server type as an
intwhere 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
-
getLastUpdateCount
boolean getLastUpdateCount()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
-
getUseMetadataCache
boolean getUseMetadataCache()Retrieves the boolean indicating whether metadata caching is enabled.- Returns:
trueif metadata caching is enabled,falseif caching is disabled
-
getUseCursors
boolean getUseCursors()Indicates whether fast forward only cursors should be used for forward only result sets.- Returns:
trueif fast forward cursors are requested
-
getUseLOBs
boolean getUseLOBs()Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types orStringandbyte[]respectively.- Returns:
trueif the default mapping should be to LOBs,falseotherwise
-
getUseNTLMv2
boolean getUseNTLMv2()Indicates whether, when doing Windows authentication to an MS SQL server, NTLMv2 should be used. When this is set to "false", LM and NTLM responses are sent to the server, which should work fine in most cases. However, some servers are configured to require LMv2 and NTLMv2. In these rare cases, this property should be set to "true". -
getUseKerberos
boolean getUseKerberos()Return whether to use Kerberos authentication for MS SQL Server. -
getAppName
String getAppName()Retrieves the application name for this connection.- Returns:
- the application name
-
getBindAddress
String getBindAddress()Retrieves the bind address for this connection.- Returns:
- the bind address
-
getBufferDir
File getBufferDir()Returns the directory where data should be buffered to.- Returns:
- the directory where data should be buffered to.
-
getBufferMaxMemory
int getBufferMaxMemory()Retrieves the maximum amount of memory in Kb to buffer for all connections.- Returns:
- the maximum amount of memory in Kb to buffer for all connections
-
getBufferMinPackets
int getBufferMinPackets()Retrieves the minimum number of packets to buffer perStatementfor this connection.- Returns:
- the minimum number of packets to buffer per
Statement
-
getDatabaseName
String getDatabaseName()Retrieves the database name for this connection.- Returns:
- the database name
-
getDomainName
String getDomainName()Retrieves the domain name for this connection.- Returns:
- the domain name
-
getInstanceName
String getInstanceName()Retrieves the instance name for this connection.- Returns:
- the instance name
-
getLoginTimeout
int getLoginTimeout()Retrieves the login timeout for this connection.- Returns:
- the login timeout
-
getSocketTimeout
int getSocketTimeout()Retrieves the socket timeout for this connection.- Returns:
- the socket timeout
-
getSocketKeepAlive
boolean getSocketKeepAlive()Retrieves whether to enable socket keep alive.- Returns:
trueif the socket keep alive is enabled
-
getProcessId
int getProcessId()Retrieves the process ID to send to a server when a connection is established.- Returns:
- the process ID
-
getMacAddress
String getMacAddress()Retrieves the MAC (ethernet) address for this connection.- Returns:
- the MAC (ethernet) address
-
getNamedPipe
boolean getNamedPipe()Retrieves the named pipe setting for this connection.- Returns:
- the named pipe setting
-
getPacketSize
int getPacketSize()Retrieves the packet size for this connection.- Returns:
- the packet size
-
getPassword
String getPassword()Retrieves the password for this connection.- Returns:
- the password
-
getPortNumber
int getPortNumber()Retrieves the port number for this connection.- Returns:
- the port number
-
getProgName
String getProgName()Retrieves the program name for this connection.- Returns:
- the program name
-
getServerName
String getServerName()Retrieves the server name for this connection.- Returns:
- the server name
-
getTcpNoDelay
boolean getTcpNoDelay()Retrieves the tcpNoDelay setting for this connection.- Returns:
- the tcpNoDelay setting
-
getUseJCIFS
boolean getUseJCIFS()Retrieves the useJCIFS setting for this connection.- Returns:
- the useJCIFS setting
-
getUser
String getUser()Retrieves the user for this connection.- Returns:
- the user
-
getWsid
String getWsid()Retrieves the workstation ID (WSID) for this connection.- Returns:
- the workstation ID (WSID)
-
unpackProperties
Transfers the properties to the local instance variables.- Parameters:
info- The connection properties Object.- Throws:
SQLException- If an invalid property value is found.
-
parseBooleanProperty
Parse a string property value into an boolean value.- Parameters:
info- The connection properties object.key- The message key used to retrieve the property name.- Returns:
- The boolean value of the string property value.
- Throws:
SQLException- If the property value can't be parsed.
-
parseIntegerProperty
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:
SQLException- If the property value can't be parsed.
-
parseLongProperty
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:
SQLException- If the property value can't be parsed.
-
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:
booleantrue if a multi byte character set
-
getCharsetInfo
Retrieve theCharsetInfoinstance used by this connection.- Returns:
- the default
CharsetInfofor this connection
-
getUseUnicode
protected boolean getUseUnicode()Retrieve the sendParametersAsUnicode flag.- Returns:
booleantrue 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
Called by the protocol to change the current character set.- Parameters:
charset- the server character set name- Throws:
SQLException
-
loadCharset
Load the Java charset to match the server character set.- Parameters:
charset- the server character set- Throws:
SQLException
-
loadCharset
Load the Java charset to match the server character set.- Parameters:
ci- theCharsetInfoto load- Throws:
SQLException
-
determineServerCharset
Discovers the server charset for server versions that do not sendENVCHANGEpackets on login ack, by executing a DB vendor/version specific query.Will throw an
SQLExceptionif used on SQL Server 7.0 or 2000; the idea is that the charset should already be determined fromENVCHANGEpackets for these DB servers.Should only be called from the constructor.
- Returns:
- the default server charset
- Throws:
SQLException- if an error condition occurs
-
setCollation
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)
- Parameters:
collation- The new collation.- Throws:
SQLException
-
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
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:
SQLException
-
setDBServerInfo
protected void setDBServerInfo(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 11databaseMinorVersion- The minor version eg 92buildNumber- The server build number.
-
removeStatement
Removes a statement object from the list maintained by the connection and cleans 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- Throws:
SQLException
-
addStatement
Adds 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- statement to add
-
checkOpen
Checks that the connection is still open.- Throws:
SQLException- if the connection is closed
-
checkLocal
Checks that this connection is in local transaction mode.- Parameters:
method- the method name being tested- Throws:
SQLException- if in XA distributed transaction mode
-
notImplemented
Reports that user tried to call a method which has not been implemented.- Parameters:
method- the method name to report in the error message- Throws:
SQLException- always, with the not implemented message
-
getDatabaseMajorVersion
public int getDatabaseMajorVersion()Retrieves the DBMS major version.- Returns:
- the version as an
int
-
getDatabaseMinorVersion
public int getDatabaseMinorVersion()Retrieves the DBMS minor version.- Returns:
- the version as an
int
-
getDatabaseProductName
String getDatabaseProductName()Retrieves the DBMS product name.- Returns:
- the name as a
String
-
getDatabaseProductVersion
String getDatabaseProductVersion()Retrieves the DBMS product version.- Returns:
- the version as a
String
-
getURL
String getURL()Retrieves the original connection URL.- Returns:
- the connection url as a
String
-
getRmHost
Retrieves 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()Forces the closed status on the statement if an I/O error has occurred. -
sendXaPacket
Invokes thexp_jtdsxaextended stored procedure on the server. Synchronized because it accesses thebaseTds.- 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:
SQLException- if an error condition occurs
-
enlistConnection
Enlists the current connection in a distributed transaction.- Parameters:
oleTranID- the OLE transaction cookie or null to delist- Throws:
SQLException- if an error condition occurs
-
setXid
Sets the XA transaction ID when running in emulation mode.- Parameters:
xid- the XA Transaction ID
-
getXid
Object getXid()Gets the XA transaction ID when running in emulation mode.- Returns:
- the transaction ID as an
Object
-
setXaState
void setXaState(int value) Sets the XA state variable.- Parameters:
value- the XA state value
-
getXaState
int getXaState()Retrieves the XA state variable.- Returns:
- the xa state variable as an
int
-
isXaEmulation
boolean isXaEmulation()Retrieves the XA Emulation flag.- Returns:
- True if in XA emulation mode.
-
getMutex
Semaphore getMutex()Retrieves the connection mutex and acquires an exclusive lock on the network connection.- Returns:
- the mutex object as a
Semaphore
-
releaseTds
Releases (either closes or caches) aTdsCore.- Parameters:
tds- theTdsCoreinstance to release- Throws:
SQLException- if an error occurs while closing or cleaning up
-
getCachedTds
TdsCore getCachedTds()Retrieves the cachedTdsCoreornullif nothing is cached and resets the cache (sets it tonull).- Returns:
- the value of
cachedTds - To do:
- Should probably synchronize on another object
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
close
Releases thisConnectionobject's database and JDBC resources immediately instead of waiting for them to be automatically released.Calling the method close on a
Connectionobject that is already closed is a no-op.Note: A
Connectionobject is automatically closed when it is garbage collected. Certain fatal errors also close aConnectionobject.Synchronized because it accesses the statement list and the
baseTds.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException- if a database access error occurs
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
isClosed
- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int type, int concurrency, int holdability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int type, int concurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int type, int concurrency, int holdability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
setSavepoint
Add a savepoint to the list maintained by this connection.- Parameters:
savepoint- The savepoint object to add.- Throws:
SQLException
-
clearSavepoints
private void clearSavepoints()Releases all savepoints. Used internally when committing or rolling back a transaction. -
releaseSavepoint
- Specified by:
releaseSavepointin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
getNextSavepointId
private int getNextSavepointId()Returns the next savepoint identifier.- Returns:
- the next savepoint identifier
-
addCachedProcedure
Add a stored procedure to the savepoint cache.- Parameters:
key- The signature of the procedure to cache.
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Throws:
SQLException
-
createBlob
- Specified by:
createBlobin interfaceConnection- Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Throws:
SQLException
-
createNClob
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
isValid
- Specified by:
isValidin interfaceConnection- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
setSchema
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-