Use it with caution or try not to use the JDBC driver of sqlserver provided by Microsoft

Source: Internet
Author: User

Microsoft is not happy to see this title. But to be honest, in commercial applications, few companies actually use Microsoft's com. Microsoft. JDBC. sqlserver. sqlserverdriver.

In fact, it is also a very occasional opportunity to discover the shortcomings of the Microsoft driver. During a porting application, the system reports errors such as [Microsoft] [sqlserver JDBC driver] resultset can not re-read row data for column. To solve this error, the tracking program was busy for a long time and did not find the problem. Only when Rs. getstring ("XXX") is specified, an error occurs (RS is a resultset object ). Now we can simulate the following environment:
Database Table: testtable
Table fields and types:
Guid char (38)
Title varchar (100)
Content text
Username varchar (20)
Query SQL statements:
Select guid, username, content, title from testtable where ····
Java code:
Rs. getstring ("guid ");
Rs. getbinarystream ("content ");
Rs. getstring ("username ");
-----------------------------------------------------------

The above code is not an honor. If you use the Microsoft driver, an error will be reported (that is, the error mentioned above ). If you trace, it must be this line: Rs. getstring ("username") throw an error.

So what if you swap the Rs. getstring ("username") and Rs. getbinarystream ("content"); positions below. The result is that it can run normally.

Why is this happening, because Microsoft's driver contains blob or clob (that is, image and text) fields. The query must be in the select order, and repeated queries are not supported.

In this case, only the driver is replaced. Many foreign third-party drivers, such as jsqlconnect and jturbo. These services are commercially available and are billed. trial versions are insufficient. If you want a free one, you can get a free one on www.freetds.com (I have not tested this free driver and I don't know if it will happen ).

For the initial description, refer to [earch]
Http://www.javaresearch.org/article/showarticle.jsp? Column = 2 & Thread = 4278]
Or [javaunion] (unfortunately, javaunion does not exist anymore)
Http://www.javaunion.org/bbs/cgi-bin/topic.cgi? Forum = 1 & topic = 15516 & show = 0

In fact, the document I want to talk about today is really a little old. As early as the previous javaunion still exists, we talked about this problem. Today, I suddenly posted it again, but I accidentally found the "complete installation and test instructions for the sqlserver2000 JDBC driver" in the database section. I thought there would be something worth your reference, and the results were quite disappointing (the article is very suitable for attention-based reference, but it is still possible to write from this point ). However, commercial applications are somewhat naive.
We hope that you will be cautious with using or try not to use the JDBC driver of sqlserver provided by Microsoft.
If you have any questions or have any errors, please correct them. You can send emails and communicate with each other.

Author: Silver Fox 999 (james999)
Mailbox: james-fly@vip.sina.com

========================================================== ========
Accept the suggestions from the blundblade brothers and add the following:

(1) If the JDBC-ODBC driver is used, it must be read once in the query order (whether there is any image or text type)
(2) If the ms SQL Server JDBC driver provided by Microsoft is used, if the query statement does not contain an image or text field, you can obtain it unordered.
(3) If the ms SQL Server JDBC driver provided by Microsoft is used and an image or text field exists in the query statement, it must be read in order, otherwise, an error such as driver] resultset can not re-read row data for column will be reported.
(4) If you do not want to query whether there are image or text fields in the statement, you can retrieve them in different sequence or repeatedly. The driver must be replaced and switched to a third party.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.