Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the data type of a ResultSet column [duplicate]

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?

like image 527
prashant Avatar asked Oct 10 '12 09:10

prashant


1 Answers

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

like image 111
Bhavik Shah Avatar answered Sep 28 '22 05:09

Bhavik Shah