FIX: You receive a java.lang.StackOverFlowError exception when you execute lots of PRINT statements through the SQL Server 2000 Driver for JDBC (894563)



The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

SYMPTOMS

If you execute lots of PRINT statements through the Microsoft SQL Server 2000 Driver for JDBC, you may receive a java.lang.StackOverFlowError exception when the statements call the getWarnings method.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next SQL Server 2000 Driver for JDBC service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
  Date         Time   Version   Size     File name
  ------------------------------------------------------
  15-Nov-2004  14:29  2.2.0044  287,110  Msbase.jar
  15-Nov-2004  14:29  2.2.0044   67,287  Mssqlserver.jar
  15-Nov-2004  14:29  2.2.0044   59,192  Msutil.jar

WORKAROUND

To work around this bug, increase the Java Virtual Machine (JVM) stack size to allow for more warnings. To do this, type java -? at a command prompt for a list of available options for your JVM.

Note You may still experience this bug if the number of warnings exceeds the available stack space.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

Compile and then run the following Java code:
import java.sql.*;
public class Test
{
	public static void main(String[] args) throws Exception
	{
		Connection conn = null;
		int number = 5000;
		boolean crash = false;
	
		try 
		{
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

			String url = "jdbc:microsoft:sqlserver://<Server>:1433;DatabaseName=master;";
			conn = DriverManager.getConnection(url, "<UserId>", "<Password>");
			conn.setReadOnly(true);
		
			// Loop until the fixed limit is reached.
			while(true && (number < 50000)) 
			{
				// Generate SQL code.
				System.out.println("\nGenerating " + number + " statements in memory.");
				StringBuffer sb = new StringBuffer("BEGIN TRANSACTION\n");
				for (int i=0; i<number; i++) 
				{
					sb.append("PRINT 'Hello world !'\n");
				}
				sb.append("COMMIT TRANSACTION\n");
			
				// Execute code.
				System.out.println("Executing code.");
				conn.clearWarnings();
				Statement stmt = conn.createStatement();
				stmt.execute(sb.toString());
			
				// Get warnings.
				System.out.println("Retrieving warning messages.");
				crash = true;
				SQLWarning warnings = stmt.getWarnings();
				crash = false;
				System.out.println("Retrieved all warnings succesfully!");
			
				// Increase the number of PRINT statements to send.
				number += 1000;
			}
		}
		catch(Exception e) 
		{
			e.printStackTrace();
		}
		finally 
		{
			if(conn != null) 
			{
				conn.close();
			}
		}

		System.out.println("\nEnded with " + (crash ? "crash on " + number + " statements processing!" : "no errors."));
	}
}
Note In this code, replace <Server>, <UserId>, and <Password> in this code with the name of your computer that is running SQL Server, your user ID, and your password.

REFERENCES

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


Modification Type:MinorLast Reviewed:10/7/2005
Keywords:kbBug kberrmsg kbJDBC kbProgramming kbDatabase kbQFE kbfix KB894563 kbAudDeveloper