PRB: "ResultSet Can Not Re-Read Row Data"' Error When Reading Data from a JDBC ResultSet Object

Article translations Article translations
Article ID: 824106 - View products that this article applies to.
Expand all | Collapse all

On This Page

SYMPTOMS

You have a Java application that uses JDBC to retrieve a ResultSet object by using the Microsoft SQL Server 2000 Driver for JDBC. When you try to read a column in the ResultSet, you may receive the following error message:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.
Note In this error message, the words "can not" are a misspelling for the word "cannot."

The column number that the error message refers to is dependent on the schema of your ResultSet object.

CAUSE

This error occurs with ResultSet objects that contain a BLOB column (for example, text, ntext, or image data types). The driver cannot return a BLOB column out of order because it does not cache all the content of BLOB data types because of size limitations.

For any row in the ResultSet, you can read any column from left to right, and each column should be read only one time. If you try to read columns out of order, or if you re-read a column from the ResultSet, you may receive the error message that the "Symptoms" section describes.
To prevent the problem, read the ResultSet columns in order.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior


Create the Test Table

  1. Start Microsoft SQL Query Analyzer.
  2. Paste the following SQL queries in Query Editor:
    use pubs;
    create table myTable (fld1 int, fld2 varchar(20), remark text);
    insert into myTable values (1, 'Joseph', 'Text for Joseph');
    insert into myTable values (2, 'Michael', 'Text for Michael');
    insert into myTable values (3, 'Thomas', 'Text for Thomas');
    
  3. On the Query menu, click Execute.
  4. Quit Microsoft SQL Query Analyzer.

Create and Test the Java Application

  1. Paste the following code in Notepad, or a t ext editor of your choice:
    import java.sql.*;
    import java.io.*;
    
    public class Class1
    {
    	public static void main (String[] args)
    	{
    		try
    		{
    			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" );
    			Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://server:1433;databasename=pubs;SelectMethod=direct", "<UserId>","<PassWd>");
    			Statement stmt = connection.createStatement();
    			String s = "SELECT fld1, fld2, remark FROM myTable";
    			ResultSet rs = null;
    			rs = stmt.executeQuery(s);
    			System.out.println("Success! The following are the rows in this query:");
    			int fld1;
    			String fld2;
    			String remark;
    			while (rs.next())
    			{
    				remark = rs.getString("remark"); //fails if in this order
    				fld1 = rs.getInt("fld1");
    				fld2 = rs.getString("fld2");
    				//remark = rs.getString("remark"); //works fine if in this order
    				System.out.println(fld1 + ", " + fld2 + ", " + remark);
    			}
    			rs.close();
    			stmt.close();
    			connection.close();
    		}
    
    		catch(Exception e)
    		{
    			System.out.println(" Exception = " + e );
    		}
    		try
    		{
    			System.out.println("Press any key to quit...");
    			System.in.read();
    		}
    		catch (Exception e)
    		{
    
    		}
    	}
    }
  2. Replace the server, <UserId> and <PassWd> in this code with the name of the computer that is running SQL Server, your user id, and your password.
  3. Save this Java code as Class1.java.
  4. Compile the Java source file that you created in Step 4, and then run the application. You receive the error message that the "Symptoms" section describes when the first getString call is made.

REFERENCES

For additional information about Microsoft JDBC, click the following article number to view the article in the Microsoft Knowledge Base:
313100 HOW TO: Get Started with Microsoft JDBC

Properties

Article ID: 824106 - Last Review: September 23, 2003 - Revision: 1.1
APPLIES TO
  • Microsoft SQL Server 2000 Driver for JDBC
Keywords: 
kberrmsg kbjdbc kbjava kbdatabase kbprb KB824106
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com