Compartir a través de


getColumns Method (SQLServerDatabaseMetaData)

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)

Parámetros

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.

Valor devuelto

A SQLServerResultSet object.

Excepciones

SQLServerException

Notas

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

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.

Nota

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.

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.

Nota

For more information about the data returned by the getColumns method, see "sp_columns (Transact-SQL)" in SQL Server Books Online.

Ejemplo

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

Vea también

Referencia

SQLServerDatabaseMetaData Class

Conceptos

SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members