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();
}
}