FIX: Unsupported Data Conversion Error Occurs When You Use a Null Timestamp in JDBC (827221)



The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

SYMPTOMS

When you try to retrieve a null Timestamp value from a ResultSet object with the Microsoft SQL Server 2000 Driver for JDBC, you may receive the following error message:
[Microsoft][SQLServer 2000 Driver for JDBC]Unsupported data conversion

CAUSE

This error occurs when you use the getTimestamp method that takes a Calendar object as an input parameter.

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 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 fix has the file attributes (or later) 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.
The Windows version of this fix has the following properties:

   Date         Time   Version            Size    File name
   --------------------------------------------------------------
   04-Mar-2003  00:51  2.2.0032          286,720  Msbase.jar
   04-Mar-2003  00:51  2.2.0032           67,041  Mssqlserver.jar
   04-Mar-2003  00:51  2.2.0032           58,903  Msutil.jar                                           

The Unix-based version of this fix has the following properties:

   Date         Time   Version            Size    File name
   --------------------------------------------------------------
   08-Apr-2003  18:53  2.2.0032          286,720  Msbase.jar
   08-Apr-2003  18:53  2.2.0032           67,041  Mssqlserver.jar
   08-Apr-2003  18:53  2.2.0032           58,903  Msutil.jar
                                         
Note Although the file dates are different for each operating system that is listed, internally the files are exactly the same. The best way to determine the version of the driver that you are using is to use the getDriverVersion method of the DatabaseMetaData interface.

WORKAROUND

Use the version of the getTimestamp method that does not take a Calendar object as an input parameter. See the comments in the code sample in this article for more information.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The version of the JDBC driver (2.2.0032) that fixes this problem also contains another fix. For additional information about another fix in the 2.2.032 version of the JDBC driver, click the following article number to view the article in the Microsoft Knowledge Base:

817419 FIX: String Output Parameters Truncated to 4000 Characters with JDBC

Steps to Reproduce the Problem

  1. Use the following SQL to create a table in your SQL Server database:
    CREATE Table JVER1timestamp (K1INT INTEGER NOT NULL,FTSTAMP DATETIME)
  2. Insert sample data with the following SQL code:
    INSERT INTO JVER1timestamp values (1, NULL)
    INSERT INTO JVER1timestamp values (2, getdate())
  3. Compile and run the following Java code to reproduce the problem:
    import java.sql.*;
    import java.util.Calendar;
    
    public class TimeStampCalendar
    {	
    	public static void main(String[] args) 
    	{
    		try 
    		{
    			// Get a connection
    			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    			// note: modify connection to reflect local database name, user name, and password                  
    			Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433;DatabaseName=pubs", "uid", "pwd");
    
    			Statement stmt = null; 
    			stmt = conn.createStatement();
    
    			//execute statement			
    			ResultSet rs = null;
    			rs= stmt.executeQuery("select FTSTAMP from JVER1timestamp order by K1INT");
    
    			while(rs.next())
    			{
    			//System.out.println(rs.getTimestamp(1)); //this version of getTimestamp does not reproduce the error
    				System.out.println(rs.getTimestamp(1,Calendar.getInstance())); 
    			}			
    		}
    		catch (Exception e) 
    		{
    			System.out.println(e.getMessage());
    		}
    	}
    }
    The following exception error and call stack occurs:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported data conversion.
            at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
            at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
            at com.microsoft.jdbc.base.BaseData.unsupportedConversion(Unknown Source)
            at com.microsoft.jdbc.base.BaseData.getTimestamp(Unknown Source)
            at com.microsoft.jdbc.base.BaseResultSet.getTimestamp(Unknown Source)
            at TimeStampCalendar.main(TimeStampCalendar.java:24)

Modification Type:MinorLast Reviewed:10/5/2005
Keywords:kbQFE KB827221 kbAudDeveloper