Java Doc for TdsCore.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » jdbc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.jdbc 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sourceforge.jtds.jdbc.TdsCore

TdsCore
public class TdsCore (Code)
This class implements the Sybase / Microsoft TDS protocol.

Implementation notes:

  1. This class, together with TdsData, encapsulates all of the TDS specific logic required by the driver.
  2. This is a ground up reimplementation of the TDS protocol and is rather simpler, and hopefully easier to understand, than the original.
  3. The layout of the various Login packets is derived from the original code and freeTds work, and incorporates changes including the ability to login as a TDS 5.0 user.
  4. All network I/O errors are trapped here, reported to the log (if active) and the parent Connection object is notified that the connection should be considered closed.
  5. Rather than having a large number of classes one for each token, useful information about the current token is gathered together in the inner TdsToken class.
  6. As the rest of the driver interfaces to this code via higher-level method calls there should be know need for knowledge of the TDS protocol to leak out of this class. It is for this reason that all the TDS Token constants are private.

author:
   Mike Hutchinson
author:
   Matt Brinkley
author:
   Alin Sinpalean
author:
   FreeTDS project
version:
   $Id: TdsCore.java,v 1.115 2007/07/08 17:28:23 bheineman Exp $


Field Summary
final public static  byteCANCEL_PKT
     TDS Cancel packet.
final public static  intDEFAULT_MIN_PKT_SIZE_TDS70
     Default minimum network packet size for TDS 7.0 and newer.
final static  byteDONE_CANCEL
     Done: Cancel acknowledgement.
final public static  intEXECUTE_SQL
    
final public static  byteLOGIN_PKT
     TDS 4.2 or 5.0 Login packet.
final public static  intMAX_PKT_SIZE
     Maximum network packet size.
final public static  intMIN_PKT_SIZE
     Minimum network packet size.
final public static  byteMSDTC_PKT
     TDS MSDTC packet.
final public static  byteMSLOGIN_PKT
     TDS 7.0 Login packet.
final public static  byteNTLMAUTH_PKT
     TDS 7.0 NTLM Authentication packet.
final public static  intPKT_HDR_LEN
     The size of the packet header.
final public static  bytePRELOGIN_PKT
     SQL 2000 prelogin negotiation packet.
final public static  intPREPARE
    
final public static  byteQUERY_PKT
     TDS 4.2 or 7.0 Query packet.
final public static  byteREPLY_PKT
     TDS Reply packet.
final public static  byteRPC_PKT
     TDS Remote Procedure Call.
final public static  intSSL_CLIENT_FORCE_ENCRYPT
     SSL Mode - Client requested force encryption.
final public static  intSSL_ENCRYPT_LOGIN
     SSL Mode - Login packet must be encrypted.
final public static  intSSL_NO_ENCRYPT
     SSL Mode - No server certificate installed.
final public static  intSSL_SERVER_FORCE_ENCRYPT
     SSL Mode - Server requested force encryption.
final public static  byteSYBQUERY_PKT
     TDS 5.0 Query packet.
final static  intSYB_BIGINT
     Sybase 15+ bigint.
final static  intSYB_BITNULL
     Sybase nullable bit type.
final static  intSYB_DATETIME
     Sybase date and time data types.
final static  intSYB_EXTCOLINFO
     Sybase extended column meta data.
final static  intSYB_LONGDATA
     Sybase char and binary > 255.
final static  intSYB_UNICODE
     Sybase univarchar etc.
final static  intSYB_UNITEXT
     Sybase 15+ unitext.
final public static  intTEMPORARY_STORED_PROCEDURES
    
final public static  intUNPREPARED
    

Constructor Summary
 TdsCore(ConnectionJDBC2 connection, SQLDiagnostic messages)
     Construct a TdsCore object.

Method Summary
 voidcancel(boolean timeout)
     Send (only) one cancel packet to the server.
public  voidcleanUp()
     Releases parameter and result set data and metadata to free up memory.
 voidclearResponseQueue()
     Empty the server response queue.
 voidclose()
     Close the TdsCore connection object and associated streams.
synchronized  voidcloseConnection()
     Inform the server that this connection is closing.
 voidconsumeOneResponse()
     Consume packets from the server response queue up to (and including) the first response terminator.
synchronized  byte[]enlistConnection(int type, byte[] oleTranID)
     Enlist the current connection in a distributed transaction or request the location of the MSDTC instance controlling the server we are connected to.
synchronized  voidexecuteSQL(String sql, String procName, ParamInfo[] parameters, boolean noMetaData, int timeOut, int maxRows, int maxFieldSize, boolean sendNow)
     Send an SQL statement with optional parameters to the server.
 SQLExceptiongetBatchCounts(ArrayList counts, SQLException sqlEx)
     Obtain the counts from a batch of SQL updates.
 ColInfo[]getColumns()
     Retrieve the current result set column descriptors.
public  SQLDiagnosticgetMessages()
     Returns the diagnostic chain for this instance.
 booleangetMoreResults()
     Get the next result set or update count from the TDS stream.
 booleangetNextRow()
     Retrieve the next data row from the result set.
 ParamInfo[]getParameters()
     Retrieve the parameter meta data from a Sybase prepare.
 IntegergetReturnStatus()
     Retrieve the return status for the current stored procedure.
 Object[]getRowData()
     Retrieve the current result set data items.
 intgetTdsVersion()
     Retrieve the TDS protocol version.
 intgetUpdateCount()
     Retrieve the update count from the current TDS token.
 booleanisDataInResultSet()
     Retrieve the status of result set.
 booleanisEndOfResponse()
     Retrieve the status of the response stream.
public static  booleanisPreparedProcedureName(String procName)
     Returns true if the specified procName is a sp_prepare or sp_prepexec handle; returns false otherwise.
Parameters:
  procName - Stored procedure to execute or null.
 booleanisResultSet()
     Retrieve the status of the next result item.
 booleanisRowData()
     Retrieve the status of the next result item.
 booleanisUpdateCount()
     Retrieve the status of the next result item.
 voidlogin(String serverName, String database, String user, String password, String domain, String charset, String appName, String progName, String wsid, String language, String macAddress, int packetSize)
     Login to the SQL Server.
 StringmicrosoftPrepare(String sql, ParamInfo[] params, boolean needCursor, int resultSetType, int resultSetConcurrency)
     Prepares the SQL for use with Microsoft server.
 voidnegotiateSSL(String instance, String ssl)
     Negotiate SSL settings with SQL 2000+ server.
 voidsetColumns(ColInfo[] columns)
     Sets the column meta data.
 voidstartBatch()
     Notifies the TdsCore that a batch is starting.
 voidsubmitSQL(String sql)
     Submit a simple SQL statement to the server and process all output.
synchronized  StringsybasePrepare(String sql, ParamInfo[] params)
     Creates a light weight stored procedure on a Sybase server.
synchronized  voidsybaseUnPrepare(String procName)
     Drops a Sybase temporary stored procedure.

Field Detail
CANCEL_PKT
final public static byte CANCEL_PKT(Code)
TDS Cancel packet.



DEFAULT_MIN_PKT_SIZE_TDS70
final public static int DEFAULT_MIN_PKT_SIZE_TDS70(Code)
Default minimum network packet size for TDS 7.0 and newer.



DONE_CANCEL
final static byte DONE_CANCEL(Code)
Done: Cancel acknowledgement.



EXECUTE_SQL
final public static int EXECUTE_SQL(Code)
Prepare SQL using sp_executesql



LOGIN_PKT
final public static byte LOGIN_PKT(Code)
TDS 4.2 or 5.0 Login packet.



MAX_PKT_SIZE
final public static int MAX_PKT_SIZE(Code)
Maximum network packet size.



MIN_PKT_SIZE
final public static int MIN_PKT_SIZE(Code)
Minimum network packet size.



MSDTC_PKT
final public static byte MSDTC_PKT(Code)
TDS MSDTC packet.



MSLOGIN_PKT
final public static byte MSLOGIN_PKT(Code)
TDS 7.0 Login packet.



NTLMAUTH_PKT
final public static byte NTLMAUTH_PKT(Code)
TDS 7.0 NTLM Authentication packet.



PKT_HDR_LEN
final public static int PKT_HDR_LEN(Code)
The size of the packet header.



PRELOGIN_PKT
final public static byte PRELOGIN_PKT(Code)
SQL 2000 prelogin negotiation packet.



PREPARE
final public static int PREPARE(Code)
Prepare SQL using sp_prepare and sp_execute



QUERY_PKT
final public static byte QUERY_PKT(Code)
TDS 4.2 or 7.0 Query packet.



REPLY_PKT
final public static byte REPLY_PKT(Code)
TDS Reply packet.



RPC_PKT
final public static byte RPC_PKT(Code)
TDS Remote Procedure Call.



SSL_CLIENT_FORCE_ENCRYPT
final public static int SSL_CLIENT_FORCE_ENCRYPT(Code)
SSL Mode - Client requested force encryption.



SSL_ENCRYPT_LOGIN
final public static int SSL_ENCRYPT_LOGIN(Code)
SSL Mode - Login packet must be encrypted.



SSL_NO_ENCRYPT
final public static int SSL_NO_ENCRYPT(Code)
SSL Mode - No server certificate installed.



SSL_SERVER_FORCE_ENCRYPT
final public static int SSL_SERVER_FORCE_ENCRYPT(Code)
SSL Mode - Server requested force encryption.



SYBQUERY_PKT
final public static byte SYBQUERY_PKT(Code)
TDS 5.0 Query packet.



SYB_BIGINT
final static int SYB_BIGINT(Code)
Sybase 15+ bigint.



SYB_BITNULL
final static int SYB_BITNULL(Code)
Sybase nullable bit type.



SYB_DATETIME
final static int SYB_DATETIME(Code)
Sybase date and time data types.



SYB_EXTCOLINFO
final static int SYB_EXTCOLINFO(Code)
Sybase extended column meta data.



SYB_LONGDATA
final static int SYB_LONGDATA(Code)
Sybase char and binary > 255.



SYB_UNICODE
final static int SYB_UNICODE(Code)
Sybase univarchar etc.



SYB_UNITEXT
final static int SYB_UNITEXT(Code)
Sybase 15+ unitext.



TEMPORARY_STORED_PROCEDURES
final public static int TEMPORARY_STORED_PROCEDURES(Code)
Prepare SQL using temporary stored procedures



UNPREPARED
final public static int UNPREPARED(Code)
Do not prepare SQL




Constructor Detail
TdsCore
TdsCore(ConnectionJDBC2 connection, SQLDiagnostic messages)(Code)
Construct a TdsCore object.
Parameters:
  connection - The connection which owns this object.
Parameters:
  messages - The SQLDiagnostic messages chain.




Method Detail
cancel
void cancel(boolean timeout)(Code)
Send (only) one cancel packet to the server.
Parameters:
  timeout - true if this is a query timeout cancel



cleanUp
public void cleanUp()(Code)
Releases parameter and result set data and metadata to free up memory.

This is useful before the TdsCore is cached for reuse.




clearResponseQueue
void clearResponseQueue() throws SQLException(Code)
Empty the server response queue.
throws:
  SQLException - if an error occurs



close
void close() throws SQLException(Code)
Close the TdsCore connection object and associated streams.



closeConnection
synchronized void closeConnection()(Code)
Inform the server that this connection is closing.

Used by Sybase a no-op for Microsoft.




consumeOneResponse
void consumeOneResponse() throws SQLException(Code)
Consume packets from the server response queue up to (and including) the first response terminator.
throws:
  SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown



enlistConnection
synchronized byte[] enlistConnection(int type, byte[] oleTranID) throws SQLException(Code)
Enlist the current connection in a distributed transaction or request the location of the MSDTC instance controlling the server we are connected to.
Parameters:
  type - set to 0 to request TM address or 1 to enlist connection
Parameters:
  oleTranID - the 40 OLE transaction ID a byte[] array containing the TM address data
throws:
  SQLException -



executeSQL
synchronized void executeSQL(String sql, String procName, ParamInfo[] parameters, boolean noMetaData, int timeOut, int maxRows, int maxFieldSize, boolean sendNow) throws SQLException(Code)
Send an SQL statement with optional parameters to the server.
Parameters:
  sql - SQL statement to execute
Parameters:
  procName - stored procedure to execute or null
Parameters:
  parameters - parameters for call or null
Parameters:
  noMetaData - suppress meta data for cursor calls
Parameters:
  timeOut - optional query timeout or 0
Parameters:
  maxRows - the maximum number of data rows to return (-1 toleave unaltered)
Parameters:
  maxFieldSize - the maximum number of bytes in a column to return(-1 to leave unaltered)
Parameters:
  sendNow - whether to send the request now or not
throws:
  SQLException - if an error occurs



getBatchCounts
SQLException getBatchCounts(ArrayList counts, SQLException sqlEx)(Code)
Obtain the counts from a batch of SQL updates.

If an error occurs Sybase will continue processing a batch consisting of TDS_LANGUAGE records whilst SQL Server will usually stop after the first error except when the error is caused by a duplicate key. Sybase will also stop after the first error when executing RPC calls. Care is taken to ensure that SQLExceptions are chained because there could be several errors reported in a batch.
Parameters:
  counts - the ArrayList containing the update counts
Parameters:
  sqlEx - any previous SQLException(s) encountered updated SQLException or null if noerror has yet occured




getColumns
ColInfo[] getColumns()(Code)
Retrieve the current result set column descriptors. The column descriptors as a ColInfo[].



getMessages
public SQLDiagnostic getMessages()(Code)
Returns the diagnostic chain for this instance.



getMoreResults
boolean getMoreResults() throws SQLException(Code)
Get the next result set or update count from the TDS stream. boolean if the next item is a result set.
throws:
  SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown



getNextRow
boolean getNextRow() throws SQLException(Code)
Retrieve the next data row from the result set. false if at the end of results, trueotherwise
throws:
  SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown



getParameters
ParamInfo[] getParameters()(Code)
Retrieve the parameter meta data from a Sybase prepare. The parameter descriptors as a ParamInfo[].



getReturnStatus
Integer getReturnStatus()(Code)
Retrieve the return status for the current stored procedure. The return status as an Integer.



getRowData
Object[] getRowData()(Code)
Retrieve the current result set data items. the row data as an Object array



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



getUpdateCount
int getUpdateCount()(Code)
Retrieve the update count from the current TDS token. The update count as an int.



isDataInResultSet
boolean isDataInResultSet() throws SQLException(Code)
Retrieve the status of result set.

This does a quick read ahead and is needed to support the isLast() method in the ResultSet. boolean - true if there is more datain the result set.




isEndOfResponse
boolean isEndOfResponse()(Code)
Retrieve the status of the response stream. boolean true if the response has been entirely consumed



isPreparedProcedureName
public static boolean isPreparedProcedureName(String procName)(Code)
Returns true if the specified procName is a sp_prepare or sp_prepexec handle; returns false otherwise.
Parameters:
  procName - Stored procedure to execute or null. true if the specified procNameis a sp_prepare or sp_prepexec handle; falseotherwise.



isResultSet
boolean isResultSet()(Code)
Retrieve the status of the next result item. boolean true if the next item is a result set.



isRowData
boolean isRowData()(Code)
Retrieve the status of the next result item. boolean true if the next item is row data.



isUpdateCount
boolean isUpdateCount()(Code)
Retrieve the status of the next result item. boolean true if the next item is an update count.



login
void login(String serverName, String database, String user, String password, String domain, String charset, String appName, String progName, String wsid, String language, String macAddress, int packetSize) throws SQLException(Code)
Login to the SQL Server.
Parameters:
  serverName - server host name
Parameters:
  database - required database
Parameters:
  user - user name
Parameters:
  password - user password
Parameters:
  domain - Windows NT domain (or null)
Parameters:
  charset - required server character set
Parameters:
  appName - application name
Parameters:
  progName - library name
Parameters:
  wsid - workstation ID
Parameters:
  language - language to use for server messages
Parameters:
  macAddress - client network MAC address
Parameters:
  packetSize - required network packet size
throws:
  SQLException - if an error occurs



microsoftPrepare
String microsoftPrepare(String sql, ParamInfo[] params, boolean needCursor, int resultSetType, int resultSetConcurrency) throws SQLException(Code)
Prepares the SQL for use with Microsoft server.
Parameters:
  sql - the SQL statement to prepare.
Parameters:
  params - the actual parameter list
Parameters:
  needCursor - true if a cursorprepare is required
Parameters:
  resultSetType - value of the resultSetType parameter whenthe Statement was created
Parameters:
  resultSetConcurrency - value of the resultSetConcurrency parameterwhenthe Statement was created name of the procedure or prepared statement handle.
exception:
  SQLException -



negotiateSSL
void negotiateSSL(String instance, String ssl) throws IOException, SQLException(Code)
Negotiate SSL settings with SQL 2000+ server.

Server returns the following values for SSL mode:

    0 = Certificate installed encrypt login packet only.
  1. 1 = Certificate installed client requests force encryption.
  2. 2 = No certificate no encryption possible.
  3. 3 = Server requests force encryption.

Parameters:
  instance - The server instance name.
Parameters:
  ssl - The SSL URL property value.
throws:
  IOException -



setColumns
void setColumns(ColInfo[] columns)(Code)
Sets the column meta data.
Parameters:
  columns - the column descriptor array



startBatch
void startBatch()(Code)
Notifies the TdsCore that a batch is starting. This is so that it knows to use sp_executesql for parameterized queries (because there's no way to prepare a statement in the middle of a batch).

Sets the TdsCore.inBatch flag.




submitSQL
void submitSQL(String sql) throws SQLException(Code)
Submit a simple SQL statement to the server and process all output.
Parameters:
  sql - the statement to execute
throws:
  SQLException - if an error is returned by the server



sybasePrepare
synchronized String sybasePrepare(String sql, ParamInfo[] params) throws SQLException(Code)
Creates a light weight stored procedure on a Sybase server.
Parameters:
  sql - SQL statement to prepare
Parameters:
  params - the actual parameter list name of the procedure
throws:
  SQLException - if an error occurs



sybaseUnPrepare
synchronized void sybaseUnPrepare(String procName) throws SQLException(Code)
Drops a Sybase temporary stored procedure.
Parameters:
  procName - the temporary procedure name
throws:
  SQLException - if an error occurs



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.