1

我正在使用 JTDS JDBC 驱动程序。版本是 1.2.4 假设我正在获取特定表的列元数据:

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
}

这是 ID 计算字段的表定义

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]
4

1 回答 1

2

根据 Java 7 的JavaDoc ,此信息以 value或空字符串(这意味着:未知)DatabaseMetaData.getColumns在列中返回。IS_GENERATEDCOLUMNYESNO

本专栏是在 JDBC 4.0 中添加的,据我所知 jTDS 驱动程序只实现了 JDBC 3.0。如果此列在 jTDS 的 ResultSet 中不存在,那么您的选择是切换到 Microsoft SQL Server JDBC 驱动程序(我假设他们的驱动程序确实支持此列),或者使用类似 (对于表中的列IDC_Currencies

SELECT is_computed
FROM sys.tables t
INNER JOIN sys.columns c
    ON c.object_id = t.object_id
WHERE t.name = 'C_Currencies'
    AND c.name = 'ID'
于 2012-12-07T14:20:38.513 回答