Microsoft KB Archive/827223

= FIX: NullPointerException when you set the Timestamp parameter to Null with JDBC =

Article ID: 827223

Article Last Modified on 12/11/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Driver for JDBC

-





SYMPTOMS
When you use the JDBC setTimestamp method, the setTime method, or the setDate method to set a parameter value to Null, you may receive a java.lang.NullPointerException exception.



RESOLUTION
Install Microsoft SQL Server 2000 Driver for JDBC Service Pack 2 (SP2).



WORKAROUND
Use the setNull method to set a parameter to Null. See the comments in the code sample in this article for more information.



STATUS
Microsoft has confirmed that this is a bug in Microsoft SQL Server 2000 Driver for JDBC version 2.2.0033. This bug was corrected in Microsoft SQL Server 2000 Driver for JDBC Service Pack 2. Note This bug does not occur with earlier versions of the driver, including Service Pack 1 (SP1). Version 2.2.003 was an interim release that was only available by contacting Microsoft Product Support Services. For additional information about the availability of version 2.2.0033 of the driver, click the following article number to view the article in the Microsoft Knowledge Base:

818504 FIX: JDBC Driver Overwrites Timestamp Parameter Values with the Last Value Set



Steps to reproduce the behavior
  Use the following SQL code to create a table in your SQL Server database: CREATE TABLE kbTestTable (col1 datetime, col2 varchar(10))   Compile and run the following Java code to reproduce the problem: import java.sql.*;

public class Class1 {   public static void main (String[] args) {       try {           Class.forName(&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;); Connection con = DriverManager.getConnection(&quot;jdbc:microsoft:sqlserver://servername:1433&quot;,&quot;uid&quot;,&quot;pwd&quot;); PreparedStatement ps = con.prepareStatement(&quot;INSERT INTO kbTestTable VALUES (?, 'newvalue')&quot;); ps.setTimestamp(1, null); //ps.setNull(1, java.sql.Types.TIMESTAMP); //use this as a workaround ps.executeUpdate; System.out.println(&quot;INSERT succeeded&quot;); con.close; }       catch (Exception ex) {           ex.printStackTrace; }   } }  The following exception and call stack occurs: java.lang.NullPointerException at com.microsoft.jdbc.base.BasePreparedStatement.setTimestamp(Unknown Source) at Class1.main(Class1.java:13) 

Keywords: kbfix kbqfe KB827223

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.