Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: The "getSQLState" method returns an incorrect SQL state code value of an exception in Microsoft SQL Server JDBC Driver 3.0




Applies to: Microsoft SQL Server Java Database Connectivity Driver 3.0

↑ Back to the top


Symptoms

Consider the following scenario:
  • You install Microsoft SQL Server JDBC Driver 3.0 on a computer.
  • You create a Java-based application that connects to a SQL Server by using the Java Database Connectivity (JDBC) driver.
  • You use the getSQLState method to catch the state code of an exception in the application.
  • You run the application.
  • A SQL Server database error occurs.
In this scenario, the application receives an incorrect state code value for the database error. 

For example, a Java-based application inserts a duplicate record in a table that contains a unique cluster index by using SQL Server JDBC Driver 3.0. In this scenario, the correct SQLState value is 23000. However, you receive the following error message that contains an incorrect SQLState value:
SQL Error Message= Cannot insert duplicate key row in object '<table name>' with unique index '<index name>'.

SQLState=S0001

SQL Error Code=2601

↑ Back to the top


Cause

This issue occurs because the SQL Server JDBC Driver 3.0 is not fully compliant with the SQL-99 standards and with the standards from X/Open.

↑ Back to the top


Resolution

Hotfix information

A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, submit a request to Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft website: Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.

Prerequisites

To apply this hotfix, you must have Microsoft SQL Server JDBC Driver 3.0 installed.

Restart information

You do not have to restart the computer after you apply this hotfix.  

Registry information

You do not have to change the registry after you apply this hotfix.

Hotfix replacement information

This hotfix does not replace any other hotfixes.

File information

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 item in Control Panel.
For all supported x86-based versions of Microsoft SQL Server JDBC Driver 3.0
File nameFile versionFile sizeDateTimePlatform
Sqljdbc.jarNot Applicable518,07115-Jul-201011:09Not Applicable
Sqljdbc4.jarNot Applicable537,30415-Jul-201011:09Not Applicable
Sqljdbc_auth.dll3.0.1301.20169,92015-Jul-201011:09x86
Sqljdbc_xa.dll3.0.1301.201102,17615-Jul-201011:09x86
For all supported x64-based versions of Microsoft SQL Server JDBC Driver 3.0
File nameFile versionFile sizeDateTimePlatform
Sqljdbc.jarNot Applicable518,07115-Jul-201011:09Not Applicable
Sqljdbc4.jarNot Applicable537,30415-Jul-201011:09Not Applicable
Sqljdbc_auth.dll3.0.1301.20187,33615-Jul-201011:09x64
Sqljdbc_xa.dll3.0.1301.201131,36815-Jul-201011:09x64
For all supported IA-64-based versions of Microsoft SQL Server JDBC Driver 3.0
File nameFile versionFile sizeDateTimePlatform
Sqljdbc.jarNot Applicable518,07115-Jul-201011:09Not Applicable
Sqljdbc4.jarNot Applicable537,30415-Jul-201011:09Not Applicable
Sqljdbc_auth.dll3.0.1301.201175,40015-Jul-201011:09IA-64
Sqljdbc_xa.dll3.0.1301.201253,72815-Jul-201011:09IA-64
For all supported UNIX-based versions of Microsoft SQL Server JDBC Driver 3.0
File nameFile versionFile sizeDateTimePlatform
Sqljdbc.jarNot Applicable518,07116-Jul-201002:09Not Applicable
Sqljdbc4.jarNot Applicable537,30416-Jul-201002:09Not Applicable
Sqljdbc_auth.dll3.0.1301.201175,40016-Jul-201002:09IA-64
Sqljdbc_xa.dll3.0.1301.201253,72816-Jul-201002:09IA-64
Sqljdbc_auth.dll3.0.1301.20187,33616-Jul-201002:09x64
Sqljdbc_xa.dll3.0.1301.201131,36816-Jul-201002:09x64
Sqljdbc_auth.dll3.0.1301.20169,92016-Jul-201002:09x86
Sqljdbc_xa.dll3.0.1301.201102,17616-Jul-201002:09x86

↑ Back to the top


More Information

How to reproduce this issue

To reproduce this issue, follow these steps:
  1. Run the following statement in SQL Server Management Studio. This statement creates a table.
    CREATE TABLE [dbo].[Tbl1](
    [Col1] [nvarchar](50) NULL
    ) ON [PRIMARY]
    GO
  2. Run the following statement in SQL Server Management Studio. This statement creates a unique clustered index.
    CREATE UNIQUE CLUSTERED INDEX [IDX_COL1] ON [dbo].[Tbl1] 
    (
    [Col1] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
  3. Run the following statement in SQL Server Management Studio. This statement inserts a record into the table.
    insert  [dbo].[Tbl1] (col1) values ('aaa') 
  4. Create a Java-based application that includes the following code, and then run the application. This code inserts a duplicate record.
      try {
    //logger.log(Level.FINE, "starting log");
    Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    String connectionUrl = "jdbc:sqlserver://<SQL Server Name>;database=<database name>;user=<Login Name>;password=<Login Password>;XOpenStates=true";
    Connection con = DriverManager.getConnection(connectionUrl);

    Statement stat = con.createStatement();

    stat.execute("insert into Tbl1 values ('aaa')");

    con.close();

    }

    catch(SQLException ex)
    {
    //logger.log(Level.FINE,"exception");

    System.out.println("SQL Error Message= " + ex.getMessage());
    String sqlState = ex.getSQLState();

    System.out.println("SQLState="+sqlState);

    System.out.println("SQL Error Code=" +ex.getErrorCode());

    }

↑ Back to the top


Status

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

↑ Back to the top


References

To download Microsoft SQL Server JDBC Driver 3.0, visit the following Microsoft website:

For more information about how to handle errors when you use Microsoft SQL Server JDBC Driver 3.0, visit the following Microsoft Developer Network (MSDN) website:


↑ Back to the top


Keywords: kb, kbexpertiseadvanced, kbsurveynew, kbfix, kbhotfixserver, kbqfe, kbautohotfix

↑ Back to the top

Article Info
Article ID : 2294405
Revision : 2
Created on : 4/9/2020
Published on : 4/9/2020
Exists online : False
Views : 92