DatabaseMetaData

TABLE_CAT

String

The catalog name.

TABLE_SCHEM

String

The table schema name.

TABLE_NAME

String

The table name.

COLUMN_NAME

String

The column name.

DATA_TYPE

short

The SQL data type from java.sql.Types.

TYPE_NAME

String

The name of the data type.

COLUMN_SIZE

int

The precision of the column.

BUFFER_LENGTH

int

Not supported by the JDBC driver.

DECIMAL_DIGITS

int

The scale of the column.

NUM_PREC_RADIX

int

The radix of the column.

NULLABLE

int

Indicates if the column is nullable. It can be one of the following values:

columnNoNulls (0)

columnNullable (1)

columnNullableUnknown (2)

REMARKS

String

The comments associated with the column.

注意注意:
SQL Server always returns null for this column.

COLUMN_DEF

String

The default value of the column.

SQL_DATA_TYPE

int

Not supported by the JDBC driver.

SQL_DATETIME_SUB

int

Not supported by the JDBC driver.

CHAR_OCTET_LENGTH

int

The maximum number of bytes in the column.

ORDINAL_POSITION

int

The index of the column within the table.

IS_NULLABLE

String

Indicates if the column allows null values.

 

 

 

 

 

例子:

public static void executeGetColumns(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      ResultSet rs = dbmd.getColumns("AdventureWorks", "Person", "Contact", "FirstName");
      ResultSetMetaData rsmd = rs.getMetaData();

      // Display the result set data.
      int cols = rsmd.getColumnCount();
      while(rs.next()) {
         for (int i = 1; i <= cols; i++) {
            System.out.println(rs.getString(i));
         }
      }
      rs.close();
   } 

   catch (Exception e) {
      e.printStackTrace();
   }
}

 

转载于:https://my.oschina.net/u/586392/blog/697865

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值