随着项目的需要,对于数据库支持要求越多越好,最好是Generic JDBC Connection。为此,笔者要求项目程序内只允许使用JDBC接口。在此条件下如何获取表的字段信息?有哪几种方式?都适用吗?
字段信息
字段在表里就是一个Column,关于Column在JDBC里面有20多个参数来描述它,称为元数据,Metadata。包括:
1.TABLE_CATString => table catalog (may be null)
2.TABLE_SCHEMString => table schema (may be null)
3.TABLE_NAMEString => table name
4.COLUMN_NAMEString => column name
5.DATA_TYPEint => SQL type from java.sql.Types
6.TYPE_NAMEString => Data source dependent type name, for a UDT the type name is fully qualified
7.COLUMN_SIZEint => column size.
8.BUFFER_LENGTHis not used.
9.DECIMAL_DIGITSint => the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable.
10.NUM_PREC_RADIXint => Radix (typically either 10 or 2)
11.