net.sourceforge.jtds.jdbc

Class ConnectionJDBC2

Implemented Interfaces:
java.sql.Connection
Known Direct 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.119 2007/07/08 21:43:02 bheineman Exp $
Authors:
Mike Hutchinson
Alin Sinpalean

Field Summary

private static String
SQL_SERVER_65_CHARSET_QUERY
SQL query to determine the server charset on MS SQL Server 6.5.
private static String
SQL_SERVER_INITIAL_SQL
SQL Server initial connection string.
private static String
SYBASE_INITIAL_SQL
Sybase initial connection string.
private static String
SYBASE_SERVER_CHARSET_QUERY
SQL query to determine the server charset on Sybase.
static int
TRANSACTION_SNAPSHOT
SQL Server custom transaction isolation level.
private 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 String
bindAddress
The local address to bind to when connecting to a database via TCP/IP.
private File
bufferDir
The directory to buffer data to
private int
bufferMaxMemory
The global buffer memory limit for all connections (in kilobytes).
private int
bufferMinPackets
The minimum number of packets per statement to buffer to memory.
private TdsCore
cachedTds
A cached TdsCore instance to reuse on new statements.
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 String
currentDatabase
The current database name.
private int
cursorSequenceNo
Cursor unique ID number.
private int
databaseMajorVersion
The major version number eg 11.
private int
databaseMinorVersion
The minor version number eg 92.
private String
databaseName
The requested database name.
private String
databaseProductName
The database product name eg SQL SERVER.
private String
databaseProductVersion
The product version eg 11.92.
private String
domainName
The Windows Domain name.
private String
instanceName
The SQL Server instance.
private 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 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 String
password
The user password.
private int
portNumber
The server port number.
private int
prepareSql
Method for preparing SQL used in Prepared Statements.
private ArrayList
procInTran
Procedures in this transaction.
private String
progName
The program name.
private boolean
readOnly
True if this connection is read only.
private int
rowCount
Connection's current rowcount limit.
private String
serverCharset
The server character set.
private 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
socketTimeout
Socket timeout value in seconds or 0.
private int
spSequenceNo
Stored procedure unique ID number.
private String
ssl
SSL setting.
private StatementCache
statementCache
Statement cache.
private ArrayList
statements
List of statements associated with this connection.
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 String
url
The orginal connection URL.
private boolean
useCursors
Use fast forward cursors for forward only result sets.
private boolean
useJCIFS
Force use of jCIFS library on Windows when connecting via named pipes.
private boolean
useLOBs
Map large types (IMAGE and TEXT/NTEXT) to LOBs by default.
private boolean
useMetadataCache
Use metadata cache for prepared statements.
private boolean
useNTLMv2
When doing NTLM authentication, send NTLMv2 response rather than regular response
private boolean
useUnicode
Send parameters as unicode.
private String
user
The database user ID.
private 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 Object
xid
Current XA Transaction ID.

Constructor Summary

ConnectionJDBC2()
Default constructor.
ConnectionJDBC2(String url, Properties info)
Create a new database connection.

Method Summary

(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
checkOpen()
Checks that the 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()
private SharedSocket
createNamedPipe(ConnectionJDBC2 connection)
Creates a SharedSocket object representing a connection to a named pipe.
Statement
createStatement()
Statement
createStatement(int type, int concurrency)
Statement
createStatement(int type, int concurrency, int holdability)
private 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)
Enlists the current connection in a distributed transaction.
(package private) String
getAppName()
Retrieves the application name for this connection.
boolean
getAutoCommit()
(package private) int
getBatchSize()
Retrieves the batch size to be used internally.
(package private) String
getBindAddress()
Retrieves the bind address for this connection.
(package private) File
getBufferDir()
Returns the directory where data should be buffered to.
(package private) int
getBufferMaxMemory()
Retrieves the maximum amount of memory in Kb to buffer for all connections.
(package private) int
getBufferMinPackets()
Retrieves the minimum number of packets to buffer per Statement for this connection.
(package private) TdsCore
getCachedTds()
Retrieves the cached TdsCore or null if nothing is cached and resets the cache (sets it to null).
String
getCatalog()
protected 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) String
getCursorName()
Retrieves the next unique cursor name.
int
getDatabaseMajorVersion()
Retrieves the DBMS major version.
int
getDatabaseMinorVersion()
Retrieves the DBMS minor version.
(package private) String
getDatabaseName()
Retrieves the database name for this connection.
(package private) String
getDatabaseProductName()
Retrieves the DBMS product name.
(package private) String
getDatabaseProductVersion()
Retrieves the DBMS product version.
(package private) String
getDomainName()
Retrieves the domain name for this connection.
int
getHoldability()
(package private) String
getInstanceName()
Retrieves the instance name for this connection.
(package private) boolean
getLastUpdateCount()
Retrieves the status of the lastUpdateCount flag.
(package private) long
getLobBuffer()
Retrieves the LOB buffer size.
(package private) int
getLoginTimeout()
Retrieves the login timeout for this connection.
(package private) String
getMacAddress()
Retrieves the MAC (ethernet) address for this connection.
(package private) int
getMaxPrecision()
Retrieves the maximum decimal precision.
(package private) int
getMaxStatements()
Retrieves the maximum statement cache size.
DatabaseMetaData
getMetaData()
(package private) Semaphore
getMutex()
Retrieves the connection mutex and acquires an exclusive lock on the network connection.
(package private) boolean
getNamedPipe()
Retrieves the named pipe setting for this connection.
(package private) int
getNetPacketSize()
Retrieves the network packet size.
(package private) int
getPacketSize()
Retrieves the packet size for this connection.
(package private) String
getPassword()
Retrieves the password for this connection.
(package private) int
getPortNumber()
Retrieves the port number for this connection.
(package private) int
getPrepareSql()
Retrieves the Prepared SQL method.
(package private) String
getProcName()
Retrieves the next unique stored procedure name.
(package private) String
getProgName()
Retrieves the program name for this connection.
String
getRmHost()
Retrieves the host and port for this connection.
(package private) int
getRowCount()
Retrieves the current row count on this connection.
(package private) String
getServerName()
Retrieves the server name for this connection.
int
getServerType()
Retrieves the server type.
(package private) SharedSocket
getSocket()
Retrive the shared socket.
(package private) int
getSocketTimeout()
Retrieves the socket timeout for this connection.
protected boolean
getSybaseInfo(int flag)
Retrieve the Sybase capability data.
(package private) boolean
getTcpNoDelay()
Retrieves the tcpNoDelay setting for this connection.
(package private) int
getTdsVersion()
Retrieve the TDS protocol version.
int
getTextSize()
Retrieves the current maximum textsize on this connection.
int
getTransactionIsolation()
Map
getTypeMap()
(package private) String
getURL()
Retrieves the original connection URL.
(package private) boolean
getUseCursors()
Indicates whether fast forward only cursors should be used for forward only result sets.
(package private) boolean
getUseJCIFS()
Retrieves the useJCIFS setting for this connection.
(package private) boolean
getUseLOBs()
Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types or String and byte[] respectively.
(package private) boolean
getUseMetadataCache()
Retrieves the boolean indicating whether metadata caching is enabled.
(package private) boolean
getUseNTLMv2()
Indicates whether, when doing Windows authentication to an MS SQL server, NTLMv2 should be used.
protected boolean
getUseUnicode()
Retrieve the sendParametersAsUnicode flag.
(package private) String
getUser()
Retrieves the user for this connection.
SQLWarning
getWarnings()
(package private) String
getWsid()
Retrieves the workstation ID (WSID) for this connection.
(package private) int
getXaState()
Retrieves the XA state variable.
(package private) Object
getXid()
Gets the XA transaction ID when running in emulation mode.
(package private) boolean
isCharsetSpecified()
Retrieves whether a specific charset was requested on creation.
boolean
isClosed()
boolean
isReadOnly()
protected boolean
isWideChar()
Retrieve the multibyte status of the current character set.
(package private) boolean
isXaEmulation()
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.
String
nativeSQL(String sql)
(package private) static void
notImplemented(String method)
Reports that user tried to call a method which has not been implemented.
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.
CallableStatement
prepareCall(String sql)
CallableStatement
prepareCall(String sql, int type, int concurrency)
CallableStatement
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.
PreparedStatement
prepareStatement(String sql)
PreparedStatement
prepareStatement(String sql, String[] columnNames)
PreparedStatement
prepareStatement(String sql, int autoGeneratedKeys)
PreparedStatement
prepareStatement(String sql, int type, int concurrency)
PreparedStatement
prepareStatement(String sql, int type, int concurrency, int holdability)
PreparedStatement
prepareStatement(String sql, int[] columnIndexes)
void
releaseSavepoint(Savepoint savepoint)
(package private) void
releaseTds(TdsCore tds)
Releases (either closes or caches) a TdsCore.
(package private) void
removeCachedProcedure(String key)
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
rollback(Savepoint savepoint)
(package private) byte[][]
sendXaPacket(args[] , byte[] data)
Invokes the xp_jtdsxa extended stored procedure on the server.
void
setAutoCommit(boolean autoCommit)
void
setCatalog(String catalog)
(package private) void
setClosed()
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
setDBServerInfo(String databaseProductName, int databaseMajorVersion, int databaseMinorVersion, int buildNumber)
Update the connection instance with information about the server.
protected void
setDatabase(String newDb, String oldDb)
Called by the protcol to change the current database context.
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.
Savepoint
setSavepoint()
Savepoint
setSavepoint(String name)
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
setXid(Object xid)
Sets the XA transaction ID when running in emulation mode.
protected void
unpackProperties(Properties info)
Transfers the properties to the local instance variables.

Field Details

SQL_SERVER_65_CHARSET_QUERY

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

SQL_SERVER_INITIAL_SQL

private static final String SQL_SERVER_INITIAL_SQL
SQL Server initial connection string. Also contains a SELECT @@MAX_PRECISION query to retrieve the maximum precision for DECIMAL/NUMERIC data.

SYBASE_INITIAL_SQL

private static final String SYBASE_INITIAL_SQL
Sybase initial connection string.

SYBASE_SERVER_CHARSET_QUERY

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

TRANSACTION_SNAPSHOT

public static final int TRANSACTION_SNAPSHOT
SQL Server custom transaction isolation level.
Field Value:
4096

appName

private String appName
The application name.

autoCommit

private boolean autoCommit
Default auto commit state.

baseTds

private final TdsCore baseTds
The cored TDS protocol object.

batchSize

private int batchSize
The maximum size of a batch.

bindAddress

private String bindAddress
The local address to bind to when connecting to a database via TCP/IP.

bufferDir

private File bufferDir
The directory to buffer data to

bufferMaxMemory

private int bufferMaxMemory
The global buffer memory limit for all connections (in kilobytes).

bufferMinPackets

private int bufferMinPackets
The minimum number of packets per statement to buffer to memory.

cachedTds

private TdsCore cachedTds
A cached TdsCore instance to reuse on new statements.

charsetInfo

private CharsetInfo charsetInfo
Java charset for encoding.

charsetSpecified

private boolean charsetSpecified
True if user specifies an explicit charset.

closed

private boolean closed
True if this connection is closed.

collation

private byte[] collation
SQL Server 2000 collation.

currentDatabase

private String currentDatabase
The current database name.

cursorSequenceNo

private int cursorSequenceNo
Cursor unique ID number.

databaseMajorVersion

private int databaseMajorVersion
The major version number eg 11.

databaseMinorVersion

private int databaseMinorVersion
The minor version number eg 92.

databaseName

private String databaseName
The requested database name.

databaseProductName

private String databaseProductName
The database product name eg SQL SERVER.

databaseProductVersion

private String databaseProductVersion
The product version eg 11.92.

domainName

private String domainName
The Windows Domain name.

instanceName

private String instanceName
The SQL Server instance.

language

private String language
The server message language.

lastUpdateCount

private boolean lastUpdateCount
Only return the last update count.

lobBuffer

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

loginTimeout

private int loginTimeout
Login timeout value in seconds or 0.

macAddress

private String macAddress
The client MAC Address.

maxPrecision

private int maxPrecision
Maximum decimal precision.

maxStatements

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

messages

private final SQLDiagnostic messages
Diagnostc messages for this connection.

mutex

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

namedPipe

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

netPacketSize

private int netPacketSize
The initial network packet size.

packetSize

private int packetSize
User requested packet size.

password

private String password
The user password.

portNumber

private int portNumber
The server port number.

prepareSql

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

procInTran

private final ArrayList procInTran
Procedures in this transaction.

progName

private String progName
The program name.

readOnly

private boolean readOnly
True if this connection is read only.

rowCount

private int rowCount
Connection's current rowcount limit.

serverCharset

private String serverCharset
The server character set.

serverName

private String serverName
The server host name.

serverType

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

socket

private final SharedSocket socket
The network TCP/IP socket.

socketTimeout

private int socketTimeout
Socket timeout value in seconds or 0.

spSequenceNo

private int spSequenceNo
Stored procedure unique ID number.

ssl

private String ssl
SSL setting.

statementCache

private StatementCache statementCache
Statement cache.

statements

private final ArrayList statements
List of statements associated with this connection.

sybaseInfo

private int sybaseInfo
Sybase capability mask.

tcpNoDelay

private boolean tcpNoDelay
TCP_NODELAY

tdsVersion

private int tdsVersion
The server protocol version.

textSize

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

transactionIsolation

private int transactionIsolation
Default transaction isolation level.

url

private final String url
The orginal connection URL.

useCursors

private boolean useCursors
Use fast forward cursors for forward only result sets.

useJCIFS

private boolean useJCIFS
Force use of jCIFS library on Windows when connecting via named pipes.

useLOBs

private boolean useLOBs
Map large types (IMAGE and TEXT/NTEXT) to LOBs by default.

useMetadataCache

private boolean useMetadataCache
Use metadata cache for prepared statements.

useNTLMv2

private boolean useNTLMv2
When doing NTLM authentication, send NTLMv2 response rather than regular response

useUnicode

private boolean useUnicode
Send parameters as unicode.

user

private String user
The database user ID.

wsid

private String wsid
Workstation ID.

xaEmulation

private boolean xaEmulation
True if driver should emulate distributed transactions.

xaState

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

xaTransaction

private boolean xaTransaction
True if running distributed transaction.

xid

private Object xid
Current XA Transaction ID.

Constructor Details

ConnectionJDBC2

private ConnectionJDBC2()
Default constructor.

Used for testing.


ConnectionJDBC2

(package private)  ConnectionJDBC2(String url,
                                   Properties info)
            throws SQLException
Create a new database connection.
Parameters:
url - The connection URL starting jdbc:jtds:.
info - The additional connection properties.

Method Details

addCachedProcedure

(package private)  void addCachedProcedure(String key,
                                           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.

addStatement

(package private)  void addStatement(JtdsStatement statement)
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

checkLocal

(package private)  void checkLocal(String method)
            throws SQLException
Checks that this connection is in local transaction mode.
Parameters:
method - the method name being tested

checkOpen

(package private)  void checkOpen()
            throws SQLException
Checks that the connection is still open.

clearSavepoints

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

clearWarnings

public void clearWarnings()
            throws SQLException

close

public void close()
            throws 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.


commit

public void commit()
            throws SQLException

createNamedPipe

private SharedSocket createNamedPipe(ConnectionJDBC2 connection)
            throws IOException
Creates a SharedSocket object representing a connection to a named pipe. If the os.name system property starts with "Windows" (case-insensitive) and the useJCIFS parameter is false, a SharedLocalNamedPipe object is created. Else a SharedNamedPipe 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 an IOException continues to be thrown stating, "All pipe instances are busy". If loginTimeout 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

createStatement

public Statement createStatement()
            throws SQLException

createStatement

public Statement createStatement(int type,
                                 int concurrency)
            throws SQLException

createStatement

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

determineServerCharset

private String determineServerCharset()
            throws 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

enlistConnection

(package private)  void enlistConnection(byte[] oleTranID)
            throws SQLException
Enlists the current connection in a distributed transaction.
Parameters:
oleTranID - the OLE transaction cookie or null to delist

getAppName

(package private)  String getAppName()
Retrieves the application name for this connection.
Returns:
the application name

getAutoCommit

public boolean getAutoCommit()
            throws SQLException

getBatchSize

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

getBindAddress

(package private)  String getBindAddress()
Retrieves the bind address for this connection.
Returns:
the bind address

getBufferDir

(package private)  File getBufferDir()
Returns the directory where data should be buffered to.
Returns:
the directory where data should be buffered to.

getBufferMaxMemory

(package private)  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

(package private)  int getBufferMinPackets()
Retrieves the minimum number of packets to buffer per Statement for this connection.
Returns:
the minimum number of packets to buffer per Statement

getCachedTds

(package private)  TdsCore getCachedTds()
Retrieves the cached TdsCore or null if nothing is cached and resets the cache (sets it to null).
Returns:
the value of cachedTds
To do:
Should probably synchronize on another object

getCatalog

public String getCatalog()
            throws SQLException

getCharset

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

getCharsetInfo

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

getCollation

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

getCursorName

(package private)  String getCursorName()
Retrieves the next unique cursor name.
Returns:
the next cursor name as a String

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

getDatabaseName

(package private)  String getDatabaseName()
Retrieves the database name for this connection.
Returns:
the database name

getDatabaseProductName

(package private)  String getDatabaseProductName()
Retrieves the DBMS product name.
Returns:
the name as a String

getDatabaseProductVersion

(package private)  String getDatabaseProductVersion()
Retrieves the DBMS product version.
Returns:
the version as a String

getDomainName

(package private)  String getDomainName()
Retrieves the domain name for this connection.
Returns:
the domain name

getHoldability

public int getHoldability()
            throws SQLException

getInstanceName

(package private)  String getInstanceName()
Retrieves the instance name for this connection.
Returns:
the instance name

getLastUpdateCount

(package private)  boolean getLastUpdateCount()
Retrieves the status of the lastUpdateCount flag.
Returns:
the lastUpdateCount flag as a boolean

getLobBuffer

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

getLoginTimeout

(package private)  int getLoginTimeout()
Retrieves the login timeout for this connection.
Returns:
the login timeout

getMacAddress

(package private)  String getMacAddress()
Retrieves the MAC (ethernet) address for this connection.
Returns:
the MAC (ethernet) address

getMaxPrecision

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

getMaxStatements

(package private)  int getMaxStatements()
Retrieves the maximum statement cache size.
Returns:
the maximum statement cache size

getMetaData

public DatabaseMetaData getMetaData()
            throws SQLException

getMutex

(package private)  Semaphore getMutex()
Retrieves the connection mutex and acquires an exclusive lock on the network connection.
Returns:
the mutex object as a Semaphore

getNamedPipe

(package private)  boolean getNamedPipe()
Retrieves the named pipe setting for this connection.
Returns:
the named pipe setting

getNetPacketSize

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

getPacketSize

(package private)  int getPacketSize()
Retrieves the packet size for this connection.
Returns:
the packet size

getPassword

(package private)  String getPassword()
Retrieves the password for this connection.
Returns:
the password

getPortNumber

(package private)  int getPortNumber()
Retrieves the port number for this connection.
Returns:
the port number

getPrepareSql

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

getProcName

(package private)  String getProcName()
Returns:
the next temporary SP name as a String

getProgName

(package private)  String getProgName()
Retrieves the program name for this connection.
Returns:
the program name

getRmHost

public 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

getRowCount

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

getServerName

(package private)  String getServerName()
Retrieves the server name for this connection.
Returns:
the server name

getServerType

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

getSocket

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

getSocketTimeout

(package private)  int getSocketTimeout()
Retrieves the socket timeout for this connection.
Returns:
the socket timeout

getSybaseInfo

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

getTcpNoDelay

(package private)  boolean getTcpNoDelay()
Retrieves the tcpNoDelay setting for this connection.
Returns:
the tcpNoDelay setting

getTdsVersion

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

getTextSize

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

getTransactionIsolation

public int getTransactionIsolation()
            throws SQLException

getTypeMap

public Map getTypeMap()
            throws SQLException

getURL

(package private)  String getURL()
Retrieves the original connection URL.
Returns:
the connection url as a String

getUseCursors

(package private)  boolean getUseCursors()
Indicates whether fast forward only cursors should be used for forward only result sets.
Returns:
true if fast forward cursors are requested

getUseJCIFS

(package private)  boolean getUseJCIFS()
Retrieves the useJCIFS setting for this connection.
Returns:
the useJCIFS setting

getUseLOBs

(package private)  boolean getUseLOBs()
Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types or String and byte[] respectively.
Returns:
true if the default mapping should be to LOBs, false otherwise

getUseMetadataCache

(package private)  boolean getUseMetadataCache()
Retrieves the boolean indicating whether metadata caching is enabled.
Returns:
true if metadata caching is enabled, false if caching is disabled

getUseNTLMv2

(package private)  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".

getUseUnicode

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

getUser

(package private)  String getUser()
Retrieves the user for this connection.
Returns:
the user

getWarnings

public SQLWarning getWarnings()
            throws SQLException

getWsid

(package private)  String getWsid()
Retrieves the workstation ID (WSID) for this connection.
Returns:
the workstation ID (WSID)

getXaState

(package private)  int getXaState()
Retrieves the XA state variable.
Returns:
the xa state variable as an int

getXid

(package private)  Object getXid()
Gets the XA transaction ID when running in emulation mode.
Returns:
the transaction ID as an Object

isCharsetSpecified

(package private)  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.

isClosed

public boolean isClosed()
            throws SQLException

isReadOnly

public boolean isReadOnly()
            throws SQLException

isWideChar

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

isXaEmulation

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

loadCharset

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

loadCharset

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

nativeSQL

public String nativeSQL(String sql)
            throws SQLException

notImplemented

(package private) static void notImplemented(String method)
            throws SQLException
Reports that user tried to call a method which has not been implemented.
Parameters:
method - the method name to report in the error message

parseIntegerProperty

private static int parseIntegerProperty(Properties info,
                                        String key)
            throws 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.

parseLongProperty

private static long parseLongProperty(Properties info,
                                      String key)
            throws 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.

prepareCall

public CallableStatement prepareCall(String sql)
            throws SQLException

prepareCall

public CallableStatement prepareCall(String sql,
                                     int type,
                                     int concurrency)
            throws SQLException

prepareCall

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

prepareSQL

(package private)  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 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:
pstmt - the target prepared statement
sql - the SQL statement to prepare
params - the parameters
returnKeys - indicates whether the statement will return generated keys
cursorNeeded - indicates whether a cursor prepare is needed
Returns:
the SQL procedure name as a String or null if the SQL cannot be prepared

prepareStatement

public PreparedStatement prepareStatement(String sql)
            throws SQLException

prepareStatement

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

prepareStatement

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

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int type,
                                          int concurrency)
            throws SQLException

prepareStatement

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

prepareStatement

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

releaseSavepoint

public void releaseSavepoint(Savepoint savepoint)
            throws SQLException

releaseTds

(package private)  void releaseTds(TdsCore tds)
            throws SQLException
Releases (either closes or caches) a TdsCore.
Parameters:
tds - the TdsCore instance to release
To do:
Should probably synchronize on another object

removeCachedProcedure

(package private)  void removeCachedProcedure(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.

removeStatement

(package private)  void removeStatement(JtdsStatement statement)
            throws SQLException
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

rollback

public void rollback()
            throws SQLException

rollback

public void rollback(Savepoint savepoint)
            throws SQLException

sendXaPacket

(package private)  byte[][] sendXaPacket(args[] ,
                                         byte[] data)
            throws SQLException
Invokes the xp_jtdsxa extended stored procedure on the server.

Synchronized because it accesses the baseTds.

Parameters:
data - option byte data eg open string xid etc.
Returns:
optional byte data eg OLE cookie

setAutoCommit

public void setAutoCommit(boolean autoCommit)
            throws SQLException

setCatalog

public void setCatalog(String catalog)
            throws SQLException

setClosed

(package private)  void setClosed()
Forces the closed status on the statement if an I/O error has occurred.

setCollation

(package private)  void setCollation(byte[] collation)
            throws 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.

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 11
databaseMinorVersion - The minor version eg 92
buildNumber - The server build number.

setDatabase

protected void setDatabase(String newDb,
                           String oldDb)
            throws 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.

setHoldability

public void setHoldability(int holdability)
            throws SQLException

setNetPacketSize

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

setReadOnly

public void setReadOnly(boolean readOnly)
            throws SQLException

setRowCount

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

setSavepoint

public Savepoint setSavepoint()
            throws SQLException

setSavepoint

public Savepoint setSavepoint(String name)
            throws SQLException

setServerCharset

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

setSybaseInfo

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

setTextSize

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

setTransactionIsolation

public void setTransactionIsolation(int level)
            throws SQLException

setTypeMap

public void setTypeMap(Map map)
            throws SQLException

setXaState

(package private)  void setXaState(int value)
Sets the XA state variable.
Parameters:
value - the XA state value

setXid

(package private)  void setXid(Object xid)
Sets the XA transaction ID when running in emulation mode.
Parameters:
xid - the XA Transaction ID

unpackProperties

protected void unpackProperties(Properties info)
            throws SQLException
Transfers the properties to the local instance variables.
Parameters:
info - The connection properties Object.

Generated on June 12 2008