FIX: Error message when you execute multiple statements in a batch command that does not return a result set in the SQL Server 2000 Driver for JDBC: "Statements that produce result sets are not allowed in batch commands" (894555)



The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

SYMPTOMS

Consider the following scenario. You use the Microsoft SQL Server 2000 Driver for JDBC to connect your program to a SQL Server database. You execute multiple statements in a batch command that does not return a result set. In this scenario, the SQL Server 2000 Driver for JDBC may incorrectly determine that the statements did return a result set. Therefore, you may receive the following error message:
Message: [Microsoft][SQLServer 2000 Driver for JDBC]Statements that produce result sets are not allowed in batch commands.

RESOLUTION

To resolve this problem, install SQL Server 2000 Driver for JDBC Service Pack 3. To obtain this service pack, visit the following Microsoft Web site:

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in SQL Server 2000 Driver for JDBC Service Pack 3.

MORE INFORMATION

For more information about JDBC, click the following article number to view the article in the Microsoft Knowledge Base:

313100 How to get started with Microsoft JDBC

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

Steps to reproduce the behavior

To reproduce this issue, compile and then run the following code sample.
import java.sql.*;

public class template

{

     public static void main(String[] args) throws Exception

     {

            java.sql.Connection  con = null;

            PreparedStatement p = null;

		 try

		 {

			 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 

			 con = java.sql.DriverManager.getConnection

				 ("jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs;selectMethod=cursor", "uid", "password");

 

			 p = con.prepareStatement("set nocount off");

			 p.addBatch();

			 p.executeBatch();

 

			 p.close();

			 p=null;

			 con.close(); con=null;

		 }

		 catch (SQLException ex)
		 {
			 while (ex != null)
			 {
				 System.out.println ("SQLState: " + ex.getSQLState ());
				 System.out.println ("Message:  " + ex.getMessage ());
				 System.out.println ("Vendor:   " + ex.getErrorCode ());
				 ex = ex.getNextException ();
				 System.out.println ("");
			 }
		 }
	
		 catch(Exception e)
		 {
			 e.printStackTrace();
			 System.out.println("Error Trace in getConnection() : " + e.getMessage());
		 }


     }

}
When you run this code sample, the following output is generated:
SQLState: HY000
Message:  [Microsoft][SQLServer 2000 Driver for JDBC]Statements that produce result sets are not allowed in batch commands.
Vendor:   0

Modification Type:MajorLast Reviewed:1/6/2006
Keywords:kbBug kbtshoot kbfix KB894555 kbAudDeveloper