ResultSet problems caused by Microsoft driver in JSP website development

Source: Internet
Author: User

When I encountered the "ResultSet can not re-read row data for column 1" issue in JSP website development JSP + sqlserver), I found that the compatibility of the original Microsoft driver was not good.

Some enthusiastic people have summarized Microsoft's shortcomings:

1) if the jdbc-odbc driver is used, the data must be read at a time 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, it can be obtained 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 order or repeatedly. Then you must replace the Microsoft driver with a third-party driver.

Solution:

Download JDTS driver support SQL6.5, 7.0, SYBASE): http://jtds.sourceforge.net/

Download and unzip to find the jtds-1.2.2.jar, put the JSP project WEB-INF/lib directory

Database connection file DbConn. java

 
 
  1. PackageCom. database;
  2. ImportJava. SQL .*;
  3.  
  4. Public ClassDbConn {
  5.  
  6. // Private static String driverName = "com. microsoft. jdbc. sqlserver. SQLServerDriver "; 
  7. // Private static String dbURL = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = jsp "; 
  8. // The original connection, jsp is the database file http://www.dwww.cn 
  9.  
  10. Private StaticString driverName ="Net. sourceforge. jtds. jdbc. Driver";
  11. Private StaticString dbURL ="Jdbc: jtds: sqlserver: // localhost: 1433/jsp";
  12.  
  13. PrivateString userName ="Dwww";
  14. PrivateString userPwd ="Dwww";
  15. PublicConnection dbConn =Null;
  16.  
  17.  
  18. Public SynchronizedConnection getConnection ()
  19. {
  20. Try 
  21. {
  22. Class. forName (driverName). newInstance ();
  23. DbConn = DriverManager. getConnection (dbURL, userName, userPwd );
  24. If(DbConn! =Null)
  25. ReturnDbConn;
  26. }
  27. Catch(Exception e)
  28. {
  29. E. printStackTrace ();
  30. Return Null;
  31. }
  32. Return Null;
  33. }
  34.  
  35.  
  36. }

OK. Solve Problems Related to ResultSet.

  1. Analysis on the advantages and disadvantages of JSP
  2. Advantages of JSP: Application Scope and Performance Comparison
  3. Flexible Use of JSP and JDBC
  4. How to Use Hidden in JSP webpage creation?
  5. How to accelerate JSP database access in JDBC

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.