Sybase JDBC Drive Improvement (JCONNECTTM for JDBC)
兕 兕 疋 疋 疋
Suitable readers:
JSP is using JSP, or develop J2EE applications;
Use Sybase SQL Server as a database server;
Requires the character set settings used by the database;
Use or not use ORM tools such as Hibernate;
If your situation is as described above, it is recommended that you read this article.
Method summary:
Establish a package class for a JDBC driver, add an improved character set and get an automatically generated number function in the packaging class.
For the platform:
Windows 2000 / XP (mainly new SHELL syntax using the new version of CMD Console)
JConnectTM 5.5
SYBASE launched JDBC driver JCONNECTTM in 2001, it seems that there is no change. The highest version is 5.5, which is designed according to J2SE 1.2 specification, and now uses more J2SE 1.4, so there are many characteristics that are not available. In particular, the implementation of JConnectTM has been troubled me until one day, when JCONNECTTM and other JDBC driver is compared, it is the BUG of JCONNECTTM!
In order to make the reader will not be troubled by the same problem, I wrote the specific improvement method for your reference:
First, you need to reverse JCONNECTTM reverse engineering (copyright infringement?
C: / jconnect> for / d / r% i in (*) do jad -s .java -d% i% I / *
Some .class files may not be unable to unable, but don't matter, because we only change a file:
COM / Sybase / JDBC2 / JDBC / SYBDRIVER.JAVA
In addition, add the following file:
COM / Sybase / JDBC2 / JDBC / CachedCharset.java
COM / Sybase / JDBC2 / JDBC / _SYBCONNECTION.JAVA
COM / Sybase / JDBC2 / JDBC / _SYBSTATEMENT.JAVA
COM / Sybase / JDBC2 / JDBC / _SYBPREPAREDSTATEMENT.JAVA
COM / Sybase / JDBC2 / JDBC / _SYBCALLABLESTATEMENT.JAVA
COM / Sybase / JDBC2 / JDBC / _SYBRESULTSET.JAVA
COM / Sybase / JDBC2 / JDBC / P_Connection.java
COM / Sybase / JDBC2 / JDBC / P_Statement.java
COM / Sybase / JDBC2 / JDBC / P_PReparedStatement.java
COM / Sybase / JDBC2 / JDBC / P_CALLABLESTATEMENT.JAVA
COM / SYBASE / JDBC2 / JDBC / P_RESULTSET.JAVA
The new file is used to implement new features. In order to distinguish two JDBCs, we agree to change the URL to the following format:
JDBC: Stupy (new attribute): Sybase: TDS:
Different from:
JDBC: Sybase: TDS:
Example:
JDBC: stupy (charset = GB2312): Sybase: TDS: 127.0.0.1: 5000 / BookStore In order to identify this new URL, find the AcceptsURL method in SybDriver.java, join:
Public Boolean AcceptsURL (String URL)
Throws SQLEXCEPTION
{
IF (Url.StartSwith ("JDBC: Stupy:"))))
Return Acceptsurl (Url.Replacefirst ("stupy //(///):", ""));
INDEX = url.indexof ('/');
IF (INDEX! = -1)
......
Similarly, add the same content in Connect (String Url, Properties Info) in SybDriver.java?
Public Final Connection Connect (String Url, Properties INFO)
Throws SQLEXCEPTION
{
String stupy_props = null;
IF (Url.StartSwith ("JDBC: Stupy)) {
stupy_props = url.substring (10, Url.indexof (":", 10));
IF (stupy_props.startswith ("))
Stupy_props = stupy_props.substring (1, stupy_props.lend "- 1);
URL = url.replacefirst ("stupy //(///) ?:" ");
}
Debug.println (this, "Connect (" URL ")");
SybProperty Props = New Sybproperty (Info, _Version);
SyburlManager umgr = new SyburlManager (URL, INFO, PROPS);
SyburlProvider Up = umgr.geturlprovider ();
IF (UP == NULL)
Return NULL;
Sybconnection conn = new SybConnection (Up, URL);
IF (_msghandler! = NULL)
Conn.setsybmessagehandler (_MSGHandler);
Java.sql.sqlwarning w = props.getwarnings ();
IF (w! = null)
Conn.handlesqle (W);
IF (stupy_props! = null)
Return New _SybConnection (conn, stupy_props);
Return conn;
}
Next, build our own characteristics. In order to highlight the focus, we need to build some auxiliary tools, including 5 middle packaging classes p_xxx, 1 simple cache-cache character category CachedCharset:
The role of the middle package is very simple, it aggregates an external object, transfer all methods to the external object. Why don't you inherit? There are several reasons, one is that Java does not support multiple inherits, and the other is to overwrite those methods that have been declared as FINAL. These five packaging classes are essentially very simple, such as packaging classes P_Resultset, which specifies a target RSULTSET instance RS that will be aggregated, and all method calls such as getString (String colname) will return RS.Getstring (colname). In order to facilitate the reader to use CP technology (COPY / PASTE), these five packaging classes are in the end of this article. Part 2èttp://www.9cbs.net/develop/read_article.asp? Id = 27124