获取ResultSet列的数据类型 [英] Getting the data type of a ResultSet column

查看:151
本文介绍了获取ResultSet列的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server.我的表中有一列的数据类型为datetime2.

我正在使用ResultSet访问表数据.我需要获取列的数据类型.对于数据库数据类型datetime2,方法rs.getColumnTypeName()返回nvarchar.

有什么办法可以同时获得datetime2Timestamp吗?

解决方案

如果您使用Java编写,则有一个类ResultSetMetaData.

您可以使用ResultSetMetaData.getColumnClassName()获取类的完全限定名称.

例如,如果数据库中的数据类型是VARCHAR,则返回的值是java.lang.String.

也请尝试使用ResultSetMetaData.getColumnLabel()-查看其是否适用于您的情况.

ResultSetMetaData的Java文档

I am using SQL Server. My table has a column with the data type datetime2.

I am accessing the table data using ResultSet. I need to get the data type of a column. The method rs.getColumnTypeName() returns nvarchar for database data type datetime2.

Is there any way to get datetime2 or Timestamp for the same?

解决方案

If you are doing it in Java, there is a class ResultSetMetaData.

You can use ResultSetMetaData.getColumnClassName() to get the fully qualified name of the class.

For example, if the datatype in database is VARCHAR, the value returned is java.lang.String.

Also try using ResultSetMetaData.getColumnLabel() - see whether its applicable in your case.

Java Documentation for ResultSetMetaData

这篇关于获取ResultSet列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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