FIX: You receive an error message in SQL Server 2000 Driver for JDBC when you submit a converted SQL statement that is generated by the Connection.nativeSQL() method to the SQL database. (894558)



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 an application to an SQL database. Then, you use the Connection.nativeSQL() method to convert an SQL statement to native SQL syntax. When you submit the converted SQL statement to the SQL database, you receive an error message. When you review the converted SQL statement that you submitted, you notice that it differs from the actual SQL statement.

CAUSE

This problem occurs because the Connection.nativeSQL() method does not return the actual SQL statement that is sent to the SQL database by the SQL Server 2000 Driver for JDBC. Therefore, you may have unintentionally submitted an incorrect SQL statement to the SQL database.

RESOLUTION

To resolve this problem, obtain SQL Server 2000 Driver for JDBC Service Pack 3 (SP 3). For more information, 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

  1. To reproduce this problem, compile and then run the following code sample:
    import java.sql.*;
    
    public class Class1
    {
    	public static void main (String[] args)
    	{
    		try
    		{
    			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    			Connection c = DriverManager.getConnection("jdbc:microsoft:sqlserver://<Server >:1433", "<UserId>", "<PassWd>");
    			String strSql = "select {fn convert(name,SQL_REAL)} from sysdatabases";
    			System.out.println( c.nativeSQL(strSql) );
    			
    			Statement stmt = c.createStatement();
    			ResultSet rs = stmt.executeQuery(strSql);
    			rs.close();
    			stmt.close();
    			c.close();
    		}
    		catch (Exception ex)
    		{
    			ex.printStackTrace();
    		}
    
    	}
    }
    Note To use this code sample, replace the following placeholders:
    • Replace Server by using the name of the instance of SQL Server.
    • Replace UserId by using your user ID.
    • Replace PassWd by using your password.


    When you run this code sample, SQL Server 2000 generates the following output:
    select {fn convert(name,SQL_REAL)} from sysdatabases
  2. Run the output that was generated by SQL Server 2000 in step 1. When you run the output, the following SQL statement is submitted to the SQL database:
    SELECT {fn CONVERT(name, SQL_SQL_REAL)} FROM sysdatabases
    When this SQL statement is submitted to the SQL database, SQL Server 2000 generates the following error message:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]'SQL_SQL_REAL' is not a recognized ODBC datatype option.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source) at Class1.main(Class1.java:17)
    SQL Server 2000 generates this error message because the code in the SQL statement that was submitted to the SQL database incorrectly states "SQL_REAL" instead of "REAL."

Modification Type:MajorLast Reviewed:9/1/2005
Keywords:kbBug kbtshoot kbfix KB894558 kbAudDeveloper