I am using JTDS JDBC Driver. Version is 1.2.4
Suppose I’m getting column metadata for particular a table:
ResultSet columnsRs = meta.getColumns(null, [pattern], [table name], null);
while(columnRs.next()){
// I would like to know here if the current column is marked computed
}
Here is the table definition for ID computed field
CREATE TABLE [dbo].[C_Currencies](
[CurrencyID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](150) NOT NULL,
[ID] AS ([CurrencyID]),
CONSTRAINT [pk_currency] PRIMARY KEY CLUSTERED
(
[CurrencyID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
According to the
DatabaseMetaData.getColumnsJavaDoc from Java 7, this information is returned in the columnIS_GENERATEDCOLUMNwith either valueYES,NOor empty string (which means: unknown).This column was added in JDBC 4.0, and as far as I know the jTDS driver only implements JDBC 3.0. If this column does not exist in the ResultSet with jTDS, then your options are either to switch to the Microsoft SQL Server JDBC driver (I assume their driver does support this column), or query the system views of SQL Server yourself using something like (for column
IDin tableC_Currencies):