Applies to: Microsoft SQL Server Java Database Connectivity Driver 3.0
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
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.
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:http://support.microsoft.com/contactus/?ws=supportNote 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 name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Sqljdbc.jar |
Not Applicable |
518,071 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc4.jar |
Not Applicable |
537,304 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc_auth.dll |
3.0.1301.201 |
69,920 |
15-Jul-2010 |
11:09 |
x86 |
Sqljdbc_xa.dll |
3.0.1301.201 |
102,176 |
15-Jul-2010 |
11:09 |
x86 |
For all supported x64-based versions of Microsoft SQL Server JDBC Driver 3.0
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Sqljdbc.jar |
Not Applicable |
518,071 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc4.jar |
Not Applicable |
537,304 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc_auth.dll |
3.0.1301.201 |
87,336 |
15-Jul-2010 |
11:09 |
x64 |
Sqljdbc_xa.dll |
3.0.1301.201 |
131,368 |
15-Jul-2010 |
11:09 |
x64 |
For all supported IA-64-based versions of Microsoft SQL Server JDBC Driver 3.0
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Sqljdbc.jar |
Not Applicable |
518,071 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc4.jar |
Not Applicable |
537,304 |
15-Jul-2010 |
11:09 |
Not Applicable |
Sqljdbc_auth.dll |
3.0.1301.201 |
175,400 |
15-Jul-2010 |
11:09 |
IA-64 |
Sqljdbc_xa.dll |
3.0.1301.201 |
253,728 |
15-Jul-2010 |
11:09 |
IA-64 |
For all supported UNIX-based versions of Microsoft SQL Server JDBC Driver 3.0
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Sqljdbc.jar |
Not Applicable |
518,071 |
16-Jul-2010 |
02:09 |
Not Applicable |
Sqljdbc4.jar |
Not Applicable |
537,304 |
16-Jul-2010 |
02:09 |
Not Applicable |
Sqljdbc_auth.dll |
3.0.1301.201 |
175,400 |
16-Jul-2010 |
02:09 |
IA-64 |
Sqljdbc_xa.dll |
3.0.1301.201 |
253,728 |
16-Jul-2010 |
02:09 |
IA-64 |
Sqljdbc_auth.dll |
3.0.1301.201 |
87,336 |
16-Jul-2010 |
02:09 |
x64 |
Sqljdbc_xa.dll |
3.0.1301.201 |
131,368 |
16-Jul-2010 |
02:09 |
x64 |
Sqljdbc_auth.dll |
3.0.1301.201 |
69,920 |
16-Jul-2010 |
02:09 |
x86 |
Sqljdbc_xa.dll |
3.0.1301.201 |
102,176 |
16-Jul-2010 |
02:09 |
x86 |
More Information
How to reproduce this issue
To reproduce this issue, follow these steps:
-
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 -
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 -
Run the following statement in SQL Server Management Studio. This statement inserts a record into the table.insert [dbo].[Tbl1] (col1) values ('aaa')
-
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()); }
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
References
To download Microsoft SQL Server JDBC Driver 3.0, visit the following Microsoft website:
Download information of Microsoft SQL Server JDBC Driver 3.0For 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: