sqlserver_user


Hi,

I have a small program to query a stored procedure in SQL Server 2000 and print out the contents of a returned date field. The program is as follows:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbcTongue Tiedqlserver://host:1433;database=db;user=u1;password=p1";
Connection con = DriverManager.getConnection(connectionUrl);
CallableStatement cbstmt = con.prepareCall(" {call stored_proc ( , )}");

cbstmt.setString(1, "value1");
cbstmt.setString(2, "value2");
ResultSet resultSet = cbstmt.executeQuery();

while (resultSet.next()) {
System.out.println(resultSet.getDate("end_date"));
}

The date field is nullable, and the records in the database are currently null. But when I run this program, I get the following exception when using version 1.2 of the MS JDBC Driver:

com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from int to DATE is unsupported.
at com.microsoft.sqlserver.jdbc.ServerDTVImpl.getValue(Unknown Source)
at com.microsoft.sqlserver.jdbc.DTV.getValue(Unknown Source)
at com.microsoft.sqlserver.jdbc.Column.getValue(Unknown Source)
at com.microsoft.sqlserver.jdbc.Column.getValue(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getDate(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getDate(Unknown Source)
at jdbc.main(jdbc.java:38)
Exception in thread "main"

This started happening when we upgraded to the new driver. Any ideas why

Thanks.



Re: getDate() throws error with MS JDBC Driver v1.2

sqlserver_user


This was resolved by adding a CAST (NULL AS DATETIME) to the stored procedure.