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 String
The application name.private boolean
Default auto commit state.private final TdsCore
The cored TDS protocol object.private int
The maximum size of a batch.private String
The local address to bind to when connecting to a database via TCP/IP.private File
The directory to buffer data toprivate int
The global buffer memory limit for all connections (in kilobytes).private int
The minimum number of packets per statement to buffer to memory.private TdsCore
A cachedTdsCore
instance to reuse on new statements.private CharsetInfo
Java charset for encoding.private boolean
True if user specifies an explicit charset.private boolean
True if this connection is closed.private byte[]
SQL Server 2000 collation.private static int[]
the number of currently open connectionsprivate String
The current database name.private int
Cursor unique ID number.private int
The major version number eg 11.private int
The minor version number eg 92.private String
The requested database name.private String
The database product name eg SQL SERVER.private String
The product version eg 11.92.private String
The Windows Domain name.private String
The SQL Server instance.private String
The server message language.private boolean
Only return the last update count.private long
The amount of LOB data to buffer in memory.private int
Login timeout value in seconds or 0.private String
The client MAC Address.private int
Maximum decimal precision.private int
The maximum number of statements to keep open.private final SQLDiagnostic
Diagnostc messages for this connection.private final Semaphore
Mutual exclusion lock to control access to connection.private boolean
Use named pipe IPC instead of TCP/IP sockets.private int
The initial network packet size.private int
User requested packet size.private String
The user password.private int
The server port number.private int
Method for preparing SQL used in Prepared Statements.private static Integer
The process ID to report to a server when connecting.private final ArrayList
Procedures in this transaction.private String
The program name.private boolean
True if this connection is read only.private int
Connection's current rowcount limit.private int
Counter for generating unique savepoint identifiersprivate Map
Maps each savepoint to a list of temp procedures created since the savepointprivate ArrayList
The list of savepoints.private String
The server character set.private String
The server host name.private int
The make of SQL Server (sybase/microsoft).private final SharedSocket
The network TCP/IP socket.private boolean
True to enable socket keep alive.private int
Socket timeout value in seconds or 0.private int
Stored procedure unique ID number.private static final String
SQL query to determine the server charset on MS SQL Server 6.5.private static final String
SQL Server initial connection string.private String
SSL setting.private StatementCache
Statement cache.private final ArrayList
List of statements associated with this connection.private static final String
Sybase initial connection string.private static final String
SQL query to determine the server charset on Sybase.private int
Sybase capability mask.private boolean
TCP_NODELAYprivate int
The server protocol version.private int
Connection's current maximum field size limit.static final int
SQL Server custom transaction isolation level.private int
Default transaction isolation level.private final String
The orginal connection URL.private boolean
Use fast forward cursors for forward only result sets.private boolean
Force use of jCIFS library on Windows when connecting via named pipes.private boolean
Force Kerberos authenticationprivate boolean
Map large types (IMAGE and TEXT/NTEXT) to LOBs by default.private boolean
Use metadata cache for prepared statements.private boolean
When doing NTLM authentication, send NTLMv2 response rather than regular responseprivate String
The database user ID.private boolean
Send parameters as unicode.private String
Workstation ID.private boolean
True if driver should emulate distributed transactions.private int
Current emulated XA State eg start/end/prepare etc.private boolean
True if running distributed transaction.private Object
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
ConstructorsModifierConstructorDescriptionprivate
Default constructor.(package private)
JtdsConnection
(String url, Properties info) Create a new database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
(package private) void
addCachedProcedure
(String key) Add a stored procedure to the savepoint cache.(package private) void
addCachedProcedure
(String key, ProcEntry proc) Add a stored procedure to the cache.(package private) void
addStatement
(JtdsStatement statement) Adds a statement object to the list maintained by the connection.(package private) void
checkLocal
(String method) Checks that this connection is in local transaction mode.(package private) void
Checks that the connection is still open.private void
Releases all savepoints.void
void
close()
Releases thisConnection
object's database and JDBC resources immediately instead of waiting for them to be automatically released.void
commit()
createArrayOf
(String typeName, Object[] elements) private SharedSocket
createNamedPipe
(JtdsConnection connection) Creates aSharedSocket
object 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 String
Discovers the server charset for server versions that do not sendENVCHANGE
packets on login ack, by executing a DB vendor/version specific query.(package private) void
enlistConnection
(byte[] oleTranID) Enlists the current connection in a distributed transaction.protected void
finalize()
Ensure all resources are released.(package private) String
Retrieves the application name for this connection.boolean
(package private) int
Retrieves the batch size to be used internally.(package private) String
Retrieves the bind address for this connection.(package private) File
Returns the directory where data should be buffered to.(package private) int
Retrieves the maximum amount of memory in Kb to buffer for all connections.(package private) int
Retrieves the minimum number of packets to buffer perStatement
for this connection.(package private) TdsCore
Retrieves the cachedTdsCore
ornull
if nothing is cached and resets the cache (sets it tonull
).protected String
Retrieve the Java charset to use for encoding.protected CharsetInfo
Retrieve theCharsetInfo
instance used by this connection.getClientInfo
(String name) (package private) byte[]
Retrieve the SQL Server 2000 default collation.(package private) String
Retrieves the next unique cursor name.int
Retrieves the DBMS major version.int
Retrieves the DBMS minor version.(package private) String
Retrieves the database name for this connection.(package private) String
Retrieves the DBMS product name.(package private) String
Retrieves the DBMS product version.(package private) String
Retrieves the domain name for this connection.int
(package private) String
Retrieves the instance name for this connection.(package private) boolean
Retrieves the status of the lastUpdateCount flag.(package private) long
Retrieves the LOB buffer size.(package private) int
Retrieves the login timeout for this connection.(package private) String
Retrieves the MAC (ethernet) address for this connection.(package private) int
Retrieves the maximum decimal precision.(package private) int
Retrieves the maximum statement cache size.(package private) Semaphore
getMutex()
Retrieves the connection mutex and acquires an exclusive lock on the network connection.(package private) boolean
Retrieves the named pipe setting for this connection.(package private) int
Retrieves the network packet size.int
private int
Returns the next savepoint identifier.(package private) int
Retrieves the packet size for this connection.(package private) String
Retrieves the password for this connection.(package private) int
Retrieves the port number for this connection.(package private) int
Retrieves the Prepared SQL method.(package private) int
Retrieves the process ID to send to a server when a connection is established.(package private) String
Retrieves the next unique stored procedure name.(package private) String
Retrieves the program name for this connection.Retrieves the host and port for this connection.(package private) int
Retrieves the current row count on this connection.(package private) String
Retrieves the server name for this connection.int
Retrieves the server type.(package private) SharedSocket
Retrive the shared socket.(package private) boolean
Retrieves whether to enable socket keep alive.(package private) int
Retrieves the socket timeout for this connection.protected boolean
getSybaseInfo
(int flag) Retrieve the Sybase capability data.(package private) boolean
Retrieves the tcpNoDelay setting for this connection.(package private) int
Retrieve the TDS protocol version.int
Retrieves the current maximum textsize on this connection.int
(package private) String
getURL()
Retrieves the original connection URL.(package private) boolean
Indicates whether fast forward only cursors should be used for forward only result sets.(package private) boolean
Retrieves the useJCIFS setting for this connection.(package private) boolean
Return whether to use Kerberos authentication for MS SQL Server.(package private) boolean
Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types orString
andbyte[]
respectively.(package private) boolean
Retrieves the boolean indicating whether metadata caching is enabled.(package private) boolean
Indicates whether, when doing Windows authentication to an MS SQL server, NTLMv2 should be used.(package private) String
getUser()
Retrieves the user for this connection.protected boolean
Retrieve the sendParametersAsUnicode flag.(package private) String
getWsid()
Retrieves the workstation ID (WSID) for this connection.(package private) int
Retrieves the XA state variable.(package private) Object
getXid()
Gets the XA transaction ID when running in emulation mode.(package private) boolean
Retrieves whether a specific charset was requested on creation.boolean
isClosed()
boolean
boolean
isValid
(int timeout) protected boolean
Retrieve the multibyte status of the current character set.boolean
isWrapperFor
(Class arg0) (package private) boolean
Retrieves the XA Emulation flag.private void
loadCharset
(String charset) Load the Java charset to match the server character set.private void
loadCharset
(CharsetInfo ci, String ref) Load the Java charset to match the server character set.(package private) static void
notImplemented
(String method) Reports that user tried to call a method which has not been implemented.private static boolean
parseBooleanProperty
(Properties info, String key) Parse a string property value into an boolean value.private static int
parseIntegerProperty
(Properties info, String key) Parse a string property value into an integer value.private static long
parseLongProperty
(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) String
prepareSQL
(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) void
releaseSavepoint
(Savepoint savepoint) (package private) void
releaseTds
(TdsCore tds) Releases (either closes or caches) aTdsCore
.(package private) void
Remove a stored procedure from the cache.(package private) void
removeStatement
(JtdsStatement statement) Removes a statement object from the list maintained by the connection and cleans up the statement cache if necessary.void
rollback()
void
(package private) byte[][]
sendXaPacket
(int[] args, byte[] data) Invokes thexp_jtdsxa
extended stored procedure on the server.void
setAutoCommit
(boolean autoCommit) void
setCatalog
(String catalog) void
setClientInfo
(String name, String value) void
setClientInfo
(Properties properties) (package private) void
Forces the closed status on the statement if an I/O error has occurred.(package private) void
setCollation
(byte[] collation) Set the default collation for this connection.protected void
setDatabase
(String newDb, String oldDb) Called by the protcol to change the current database context.protected void
setDBServerInfo
(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
setNetworkTimeout
(Executor executor, int milliseconds) void
setReadOnly
(boolean readOnly) (package private) void
setRowCount
(int count) Sets the current row count on this connection.setSavepoint
(String name) private void
setSavepoint
(SavepointImpl savepoint) Add a savepoint to the list maintained by this connection.void
protected void
setServerCharset
(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
(Map map) (package private) void
setXaState
(int value) Sets the XA state variable.(package private) void
Sets the XA transaction ID when running in emulation mode.protected void
unpackProperties
(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, wait
Methods 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_PRECISION
query 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 cachedTdsCore
instance 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 aSharedSocket
object representing a connection to a named pipe. If theos.name
system property starts with "Windows" (case-insensitive) and theuseJCIFS
parameter isfalse
, aSharedLocalNamedPipe
object is created. Else aSharedNamedPipe
is created which uses jCIFS to provide a pure-Java implementation of Windows named pipes.This method will retry for
loginTimeout
seconds to create a named pipe if anIOException
continues to be thrown stating, "All pipe instances are busy". IfloginTimeout
is 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 anIOException
is thrown with a message stating "All pipe instances are busy", then the method timed out afterloginTimeout
milliseconds attempting to create a named pipe.
-
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
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
String
or 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
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
-
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:
true
if metadata caching is enabled,false
if caching is disabled
-
getUseCursors
boolean getUseCursors()Indicates whether fast forward only cursors should be used for forward only result sets.- Returns:
true
if fast forward cursors are requested
-
getUseLOBs
boolean getUseLOBs()Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types orString
andbyte[]
respectively.- Returns:
true
if the default mapping should be to LOBs,false
otherwise
-
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 perStatement
for 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:
true
if 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:
boolean
true if a multi byte character set
-
getCharsetInfo
Retrieve theCharsetInfo
instance used by this connection.- Returns:
- the default
CharsetInfo
for this connection
-
getUseUnicode
protected boolean getUseUnicode()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
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
- theCharsetInfo
to load- Throws:
SQLException
-
determineServerCharset
Discovers the server charset for server versions that do not sendENVCHANGE
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 fromENVCHANGE
packets 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_jtdsxa
extended 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
- theTdsCore
instance to release- Throws:
SQLException
- if an error occurs while closing or cleaning up
-
getCachedTds
TdsCore getCachedTds()Retrieves the cachedTdsCore
ornull
if 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:
getHoldability
in interfaceConnection
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
-
close
Releases thisConnection
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 aConnection
object.Synchronized because it accesses the statement list and the
baseTds
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
- if a database access error occurs
-
commit
- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
-
isClosed
- Specified by:
isClosed
in interfaceConnection
- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnly
in interfaceConnection
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnly
in interfaceConnection
- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalog
in interfaceConnection
- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfaceConnection
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int type, int concurrency, int holdability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int type, int concurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int type, int concurrency, int holdability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in 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:
releaseSavepoint
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in 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:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
createBlob
- Specified by:
createBlob
in interfaceConnection
- Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Throws:
SQLException
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
isValid
- Specified by:
isValid
in interfaceConnection
- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
setSchema
- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-