JTDS incorrectly reports data type information in result set metadata (for DATE columns, NVARCHAR reports)

Currently, the jTDS JDBC driver (1.2.5) for Microsoft SQL Server 2008 seems to incorrectly report the data type for DATE columns as NVARCHAR.

It probably works the same for both early versions of jTDS and SQL Server (2005, 2000)

  • Are there any workarounds for this that don't require switching to another driver (for example, Microsoft's own driver) or a jTDS driver fix?

  • Also, I would like to avoid the need to execute queries on the data dictionary (INFORMATION_SCHEMA.COLUMNS view, etc.) to search for data type information (and possibly cross reference output " exec sp_datatype_info " to get SQL data types)

A quick look at incomprehensible jTDS errors does not indicate whether this will be fixed or not.

The answer to this question is: JDBC - JTDS Error? For columns of type date and time (x), this does not seem to occur in SQL Server 2005.

Thanks in advance.

+2
source share
1 answer

I found a solution with the condition

metaData.getColumnType(columnNumber) == 12

if this condition is met, run the query

SELECT System_Type_Id FROM Sys.Columns WHERE Name = [column name] AND Object_Id = (SELECT Object_Id FROM Sys.Tables WHERE Name = [table name])

for smalldatetime it will return 58

and for datetime it will return 61 .

+1
source

All Articles