jTDS incorrectly reports data type info in result set metadata (for DATE columns, reports NVARCHAR)

橙三吉。 提交于 2019-12-20 03:48:09

问题


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

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

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

  • Also I would like to avoid having to perform queries against the data dictionary (INFORMATION_SCHEMA.COLUMNS view, etc.) to look up the data type information (and possibly cross-referencing against the output of "exec sp_datatype_info" in order to retrieve the SQL data types)

A quick perusal of the jTDS outstanding bugs doesn't indicate whether this will be fixed or not.

An answer to this question: JDBC - JTDS bug ? For columns of type date and time(x) seems to indicate that this doesn't occur in SQL Server 2005.

Thanks in advance.


回答1:


I found a solution with the condition

metaData.getColumnType(columnNumber) == 12

if this condition is satisfied, execute 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.



来源:https://stackoverflow.com/questions/10503715/jtds-incorrectly-reports-data-type-info-in-result-set-metadata-for-date-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!