Retrieves a description of the table columns that are available in the specified catalog.
public java.sql.ResultSet getColumns(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String col)
Parameters
catalog
A string that contains the catalog name.
schema
A string that contains the schema name pattern.
table
A string that contains the table name pattern.
col
A string that contains the column name pattern.
Return Value
A SQLServerResultSet object.
Exceptions
Remarks
This getColumns method is specified by the getColumns method in the java.sql.DatabaseMetaData interface.
The result set returned by the getColumns method will contain the following information:
Name | Type | Description |
---|---|---|
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 |
integer |
The precision of the column. |
BUFFER_LENGTH |
integer |
Not supported by the JDBC driver. |
DECIMAL_DIGITS |
integer |
The scale of the column. |
NUM_PREC_RADIX |
integer |
The radix of the column. |
NULLABLE |
integer |
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. Note:
SQL Server always returns null for this column.
|
COLUMN_DEF |
string |
The default value of the column. |
SQL_DATA_TYPE |
integer |
Not supported by the JDBC driver. |
SQL_DATETIME_SUB |
integer |
Not supported by the JDBC driver. |
CHAR_OCTET_LENGTH |
integer |
The maximum number of bytes in the column. |
ORDINAL_POSITION |
integer |
The index of the column within the table. |
IS_NULLABLE |
string |
Indicates if the column allows null values. |
SCOPE_CATALOG |
string |
Not supported by the JDBC driver. |
SCOPE_SCHEMA |
string |
Not supported by the JDBC driver. |
SCOPE_TABLE |
string |
Not supported by the JDBC driver. |
SOURCE_DATA_TYPE |
short |
Not supported by the JDBC driver. |
Example
The following example demonstrates how to use the getColumns method to return information for the FirstName column in the Person.Contact table in the SQL Server 2005 AdventureWorks sample database.
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(); } }