"conversion from int to DATE is unsupported" when calling ResultSet.getDate() on a result containing a NULL literal
See original GitHub issueDriver version or jar name
com.microsoft.sqlserver:mssql-jdbc:6.2.1.jre8
SQL Server version
Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copyright © Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3 <X64> (Build 14393: )
Client operating system
Windows 10
Java/JVM version
java version “1.8.0_131” Java™ SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot™ 64-Bit Server VM (build 25.131-b11, mixed mode)
Table schema
N/A
Problem description
Calling ResultSet.getDate()
should work on all NULL
values, regardless of their type.
Expected behavior and actual behavior
Expected:
assertNull(rs.getDate(1));
I’ve tried the repro code on MySQL, H2, Oracle (including a from dual
clause, of course), PostgreSQL, and it always works as expected.
Actual:
com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from int to DATE is unsupported.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:227)
at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java:1612)
at com.microsoft.sqlserver.jdbc.ServerDTVImpl.getValue(dtv.java:3779)
at com.microsoft.sqlserver.jdbc.DTV.getValue(dtv.java:286)
at com.microsoft.sqlserver.jdbc.Column.getValue(Column.java:189)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1925)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1906)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getDate(SQLServerResultSet.java:2057)
at SQLServer.main(SQLServer.java:62)
Repro code
try (Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select null")) {
while (rs.next())
System.out.println(rs.getDate(1));
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
conversion from int to DATE is unsupported on null date
This approach uses a magic number (date) to indicate null values, true. It's not pretty but it is quick and straightforward.
Read more >Running a simple PreparedStatement with a predicate (? IS ...
IS NULL), returns "Unsupported data conversion" with the Progress DataDirect for JDBC ... In this instance a DATE literal is being passed.
Read more >Data conversion parameters - Amazon Redshift
This parameter applies only to TIMESTAMP and DATE columns. Always use ACCEPTANYDATE with the DATEFORMAT parameter. If the date format for the data...
Read more >CallableStatement (Java SE 18 & JDK 18) - Oracle Help Center
Retrieves the value of the designated JDBC DATE parameter as a java.sql.Date object, using the given Calendar object to construct the date. Date....
Read more >Chapter 4. Built In Functions - HSQLDB
Handling of null values in the CONCAT function depends on the database property sql.concat_nulls ( SET DATABASE SQL SYNTAX CONCAT NULLS ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@v-afrafi Thanks for the quick fix. As far as I’m concerned, I’ll trust you on your judgment and wait until the release of this issue - I’m not in a hurry 😃
Thanks again
@lukaseder This fix was made with 6.3.3.jre*-preview and will be included in the next production ready release (version 6.4.0) . Thanks for the idea, will definitely keep that information on the issues as well!