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.
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.
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.
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.
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.
statement
- statement to add
checkLocal
(package private) void checkLocal(String method)
throws SQLException
Checks that this connection is in local transaction mode.
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.
connection
- the connection object
- 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.
- the default server charset
enlistConnection
(package private) void enlistConnection(byte[] oleTranID)
throws SQLException
Enlists the current connection in a distributed transaction.
oleTranID
- the OLE transaction cookie or null to delist
getAppName
(package private) String getAppName()
Retrieves the application name for this connection.
getAutoCommit
public boolean getAutoCommit()
throws SQLException
getBatchSize
(package private) int getBatchSize()
Retrieves the batch size to be used internally.
getBindAddress
(package private) String getBindAddress()
Retrieves the bind address for this connection.
getBufferDir
(package private) File getBufferDir()
Returns the directory where data should be buffered to.
- 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.
- 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.
- 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
).
- Should probably synchronize on another object
getCatalog
public String getCatalog()
throws SQLException
getCharset
protected String getCharset()
Retrieve the Java charset to use for encoding.
- the Charset name as a
String
getCharsetInfo
protected CharsetInfo getCharsetInfo()
Retrieve the CharsetInfo
instance used by this connection.
- the default
CharsetInfo
for this connection
getCollation
(package private) byte[] getCollation()
Retrieve the SQL Server 2000 default collation.
- The collation as a
byte[5]
.
getCursorName
(package private) String getCursorName()
Retrieves the next unique cursor name.
- the next cursor name as a
String
getDatabaseMajorVersion
public int getDatabaseMajorVersion()
Retrieves the DBMS major version.
getDatabaseMinorVersion
public int getDatabaseMinorVersion()
Retrieves the DBMS minor version.
getDatabaseName
(package private) String getDatabaseName()
Retrieves the database name for this connection.
getDatabaseProductName
(package private) String getDatabaseProductName()
Retrieves the DBMS product name.
getDatabaseProductVersion
(package private) String getDatabaseProductVersion()
Retrieves the DBMS product version.
getDomainName
(package private) String getDomainName()
Retrieves the domain name for this connection.
getHoldability
public int getHoldability()
throws SQLException
getInstanceName
(package private) String getInstanceName()
Retrieves the instance name for this connection.
getLastUpdateCount
(package private) boolean getLastUpdateCount()
Retrieves the status of the lastUpdateCount flag.
- the lastUpdateCount flag as a
boolean
getLobBuffer
(package private) long getLobBuffer()
Retrieves the LOB buffer size.
- the LOB buffer size as a
long
getLoginTimeout
(package private) int getLoginTimeout()
Retrieves the login timeout for this connection.
getMacAddress
(package private) String getMacAddress()
Retrieves the MAC (ethernet) address for this connection.
- the MAC (ethernet) address
getMaxPrecision
(package private) int getMaxPrecision()
Retrieves the maximum decimal precision.
getMaxStatements
(package private) int getMaxStatements()
Retrieves the maximum statement cache size.
- 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.
- the mutex object as a
Semaphore
getNamedPipe
(package private) boolean getNamedPipe()
Retrieves the named pipe setting for this connection.
getNetPacketSize
(package private) int getNetPacketSize()
Retrieves the network packet size.
- the packet size as an
int
getPacketSize
(package private) int getPacketSize()
Retrieves the packet size for this connection.
getPassword
(package private) String getPassword()
Retrieves the password for this connection.
getPortNumber
(package private) int getPortNumber()
Retrieves the port number for this connection.
getPrepareSql
(package private) int getPrepareSql()
Retrieves the Prepared SQL method.
getProcName
(package private) 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.
Not synchronized because it's only called from the synchronized
prepareSQL(JtdsPreparedStatement,String,ParamInfo[],boolean,boolean)
method.
- the next temporary SP name as a
String
getProgName
(package private) String getProgName()
Retrieves the program name for this connection.
getRmHost
public String getRmHost()
Retrieves the host and port for this connection.
Used to identify same resource manager in XA transactions.
- the hostname and port as a
String
getRowCount
(package private) int getRowCount()
Retrieves the current row count on this connection.
getServerName
(package private) String getServerName()
Retrieves the server name for this connection.
getServerType
public int getServerType()
Retrieves the server type.
- the server type as an
int
where 1 == SQLSERVER and
2 == SYBASE.
getSocket
(package private) SharedSocket getSocket()
Retrive the shared socket.
getSocketTimeout
(package private) int getSocketTimeout()
Retrieves the socket timeout for this connection.
getSybaseInfo
protected boolean getSybaseInfo(int flag)
Retrieve the Sybase capability data.
- Capability bit mask as an
int
.
getTcpNoDelay
(package private) boolean getTcpNoDelay()
Retrieves the tcpNoDelay setting for this connection.
getTdsVersion
(package private) int getTdsVersion()
Retrieve the TDS protocol version.
- The TDS version as an
int
.
getTextSize
public int getTextSize()
Retrieves the current maximum textsize on this connection.
- 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.
- 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.
true
if fast forward cursors are requested
getUseJCIFS
(package private) boolean getUseJCIFS()
Retrieves the useJCIFS setting for this connection.
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.
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.
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.
boolean
true if parameters should be sent as unicode.
getUser
(package private) String getUser()
Retrieves the user for this connection.
getWarnings
public SQLWarning getWarnings()
throws SQLException
getWsid
(package private) String getWsid()
Retrieves the workstation ID (WSID) for this connection.
- the workstation ID (WSID)
getXaState
(package private) int getXaState()
Retrieves the XA state variable.
- the xa state variable as an
int
getXid
(package private) Object getXid()
Gets the XA transaction ID when running in emulation mode.
- 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.
boolean
true if a multi byte character set
isXaEmulation
(package private) boolean isXaEmulation()
Retrieves the XA Emulation flag.
- True if in XA emulation mode.
loadCharset
private void loadCharset(String charset)
throws SQLException
Load the Java charset to match the server character set.
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.
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.
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.
info
- The connection properties object.key
- The message key used to retrieve the property name.
- 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.
info
- The connection properties object.key
- The message key used to retrieve the property name.
- 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.
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
- 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
.
tds
- the TdsCore
instance to release
- 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.
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
.
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
.
data
- option byte data eg open string xid etc.
- 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.
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.
databaseProductName
- The server name eg SQL Server.databaseMajorVersion
- The major version eg 11databaseMinorVersion
- The minor version eg 92buildNumber
- The server build number.
setDatabase
protected void setDatabase(String newDb,
String oldDb)
throws SQLException
Called by the protcol to change the current database context.
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.
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.
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.
charset
- the server character set name
setSybaseInfo
protected void setSybaseInfo(int mask)
Set the Sybase capability data.
mask
- The capability bit mask.
setTextSize
public void setTextSize(int textSize)
Sets the current maximum textsize on this connection.
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.
value
- the XA state value
setXid
(package private) void setXid(Object xid)
Sets the XA transaction ID when running in emulation mode.
xid
- the XA Transaction ID
unpackProperties
protected void unpackProperties(Properties info)
throws SQLException
Transfers the properties to the local instance variables.
info
- The connection properties Object.