jTDS错误地报告了结果集元数据中的数据类型信息(对于DATE列,报告了NVARCHAR) [英] jTDS incorrectly reports data type info in result set metadata (for DATE columns, reports NVARCHAR)

查看:160
本文介绍了jTDS错误地报告了结果集元数据中的数据类型信息(对于DATE列,报告了NVARCHAR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,针对Microsoft SQL Server 2008的jTDS JDBC驱动程序(1.2.5)似乎错误地将DATE列的数据类型报告为NVARCHAR.

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.

对于jTDS的早期版本和SQL Server(2005、2000),其行为可能都相同.

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

  • 是否有任何变通办法,不需要切换到其他驱动程序(例如Microsoft自己的驱动程序)或修补jTDS驱动程序?

  • 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?

我还想避免不得不对数据字典(INFORMATION_SCHEMA.COLUMNS视图等)执行查询以查找数据类型信息(以及可能与""的输出进行交叉引用) exec sp_datatype_info "以检索SQL数据类型)

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)

快速浏览jTDS突出的错误并不能说明是否会解决此问题.

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

此问题的答案: JDBC-JTDS漏洞 ?对于日期和时间(x)类型的列似乎表明在SQL Server 2005中不会发生这种情况.

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.

谢谢.

推荐答案

我找到了符合条件的解决方案

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])

对于smalldatetime,它将返回58

,对于datetime,它将返回61.

这篇关于jTDS错误地报告了结果集元数据中的数据类型信息(对于DATE列,报告了NVARCHAR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆