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
- PackageCom. database;
- ImportJava. SQL .*;
-
- Public ClassDbConn {
-
- // Private static String driverName = "com. microsoft. jdbc. sqlserver. SQLServerDriver ";
- // Private static String dbURL = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = jsp ";
- // The original connection, jsp is the database file http://www.dwww.cn
-
- Private StaticString driverName ="Net. sourceforge. jtds. jdbc. Driver";
- Private StaticString dbURL ="Jdbc: jtds: sqlserver: // localhost: 1433/jsp";
-
- PrivateString userName ="Dwww";
- PrivateString userPwd ="Dwww";
- PublicConnection dbConn =Null;
-
-
- Public SynchronizedConnection getConnection ()
- {
- Try
- {
- Class. forName (driverName). newInstance ();
- DbConn = DriverManager. getConnection (dbURL, userName, userPwd );
- If(DbConn! =Null)
- ReturnDbConn;
- }
- Catch(Exception e)
- {
- E. printStackTrace ();
- Return Null;
- }
- Return Null;
- }
-
-
- }
OK. Solve Problems Related to ResultSet.
- Analysis on the advantages and disadvantages of JSP
- Advantages of JSP: Application Scope and Performance Comparison
- Flexible Use of JSP and JDBC
- How to Use Hidden in JSP webpage creation?
- How to accelerate JSP database access in JDBC