Microsoft KB Archive/894555

= 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: &quot;Statements that produce result sets are not allowed in batch commands&quot; =

Article ID: 894555

Article Last Modified on 1/6/2006

-

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:

http://www.microsoft.com/downloads/details.aspx?FamilyID=07287b11-0502-461a-b138-2aa54bfdc03a&DisplayLang=en



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; 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(&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;);

con = java.sql.DriverManager.getConnection

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

p = con.prepareStatement(&quot;set nocount off&quot;);

p.addBatch;

p.executeBatch;

p.close;

p=null;

con.close; con=null;

}

catch (SQLException ex) {            while (ex != null) {                System.out.println (&quot;SQLState: &quot; + ex.getSQLState ); System.out.println (&quot;Message: &quot; + ex.getMessage ); System.out.println (&quot;Vendor:  &quot; + ex.getErrorCode ); ex = ex.getNextException ; System.out.println (&quot;&quot;); }        }         catch(Exception e)         { e.printStackTrace; System.out.println(&quot;Error Trace in getConnection : &quot; + 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

Keywords: kbtshoot kbbug kbfix KB894555

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.