jtds.jar 中的日期返回错误的数据类型
我在 MS SQL Server 上有一个表,其中有一列的数据类型为日期。我正在使用 jtds.jar 与 DB 进行 JDBC 连接。我正在从 Connection 获取 DatabaseMetaData。在检查 DatabaseMetaData 中的列时,我观察到
int iType = rsMeta.getInt("DATA_TYPE");
返回的列类型为 java.sql.Types.VARCHAR,它是字符串而不是日期。但它也返回
String tmp = rsMeta.getString("TYPE_NAME");
类型名称作为日期。
但对于 Oracle,它返回日期数据类型为 java.sql.Types.DATE。
为什么会有这样的差异呢?
I have a table on MS SQL Server with a column having data type as date. I am using jtds.jar for JDBC connection with DB. I am taking DatabaseMetaData from Connection. While checking columns from DatabaseMetaData, I observed that
int iType = rsMeta.getInt("DATA_TYPE");
returns Column type as java.sql.Types.VARCHAR
which is a string and not date. but it also returns
String tmp = rsMeta.getString("TYPE_NAME");
type name as date.
But for Oracle, It returns the date datatype as java.sql.Types.DATE
.
Why is such a difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个已知的 JTDS 错误,请参阅 http://sourceforge.net/p/jtds/bugs/ 679/。
This is a known JTDS bug, see http://sourceforge.net/p/jtds/bugs/679/.
对于 jTDS 1.3.1,这似乎仍然是一个悬而未决的问题。我可以通过直接查询 SQL Server 表目录来查找我正在使用的表,并获取该表的日期列列表来解决此问题:
一旦获得此列表,您可以显式检查并查看该列是否是日期类型:
因此,假设我有一个包含三列的示例表:
当使用 jTDS 运行时,此代码将打印以下值:
这并不理想,但它应该适用于其他有类似问题的人。
This still appears to be an open issue with jTDS 1.3.1. I was able to work around it by querying the SQL Server table catalog directly for the tables I'm working with, and getting a list of date columns for the table:
Once you have this list, you can explicitly check and see if the column is a date type:
So, say I have a sample table with three columns:
This code will print the following values when run with jTDS:
It's not ideal, but it should work for others with a similar problem.