Getting the data type of a ResultSet column

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

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

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

+7
source share
1 answer

If you do this in Java, there is a class called ResultSetMetaData .

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

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

Also try using ResultSetMetaData.getColumnLabel() - see if it is applicable in your case.

Java Documentation for ResultSetMetaData

+10
source

All Articles