java中getcolumns的参数,getColumns 方法 (SQLServerDatabaseMetaData)

getColumns 方法 (SQLServerDatabaseMetaData)getColumns Method (SQLServerDatabaseMetaData)

01/19/2017

本文内容

检索指定目录中可用的表列的说明。Retrieves a description of the table columns that are available in the specified catalog.

语法Syntax

public java.sql.ResultSet getColumns(java.lang.String catalog,

java.lang.String schema,

java.lang.String table,

java.lang.String col)

parametersParameters

catalogcatalog

一个包含目录名称的字符串 。A String that contains the catalog name.

schemaschema

一个包含架构名称模式的字符串 。A String that contains the schema name pattern.

tabletable

一个包含表名称模式的字符串 。A String that contains the table name pattern.

colcol

一个包含列名称模式的字符串 。A String that contains the column name pattern.

返回值Return Value

例外Exceptions

备注Remarks

此 getColumns 方法是由 java.sql.DatabaseMetaData 接口中的 getColumns 方法指定的。This getColumns method is specified by the getColumns method in the java.sql.DatabaseMetaData interface.

由 getColumns 方法返回的结果集将包含以下信息:The result set returned by the getColumns method will contain the following information:

名称Name

类型Type

说明Description

TABLE_CATTABLE_CAT

字符串String

目录名称。The catalog name.

TABLE_SCHEMTABLE_SCHEM

字符串String

表架构名称。The table schema name.

TABLE_NAMETABLE_NAME

字符串String

表名称。The table name.

COLUMN_NAMECOLUMN_NAME

字符串String

列名称。The column name.

DATA_TYPEDATA_TYPE

smallintsmallint

来自 java.sql.Types 的 SQL 数据类型。The SQL data type from java.sql.Types.

TYPE_NAMETYPE_NAME

字符串String

数据类型的名称。The name of the data type.

COLUMN_SIZECOLUMN_SIZE

intint

列的精度。The precision of the column.

BUFFER_LENGTHBUFFER_LENGTH

smallintsmallint

数据的传输大小。Transfer size of the data.

DECIMAL_DIGITSDECIMAL_DIGITS

smallintsmallint

列的小数位数。The scale of the column.

NUM_PREC_RADIXNUM_PREC_RADIX

smallintsmallint

列的基数。The radix of the column.

NULLABLENULLABLE

smallintsmallint

指示列是否可以为 Null。Indicates if the column is nullable. 可以为下列值之一:It can be one of the following values:

columnNoNulls (0)columnNoNulls (0)

columnNullable (1)columnNullable (1)

REMARKSREMARKS

字符串String

与列关联的注释。The comments associated with the column.

注意: 对于此列,SQL ServerSQL Server 始终会返回 null。Note: SQL ServerSQL Server always returns null for this column.

COLUMN_DEFCOLUMN_DEF

字符串String

列的默认值。The default value of the column.

SQL_DATA_TYPESQL_DATA_TYPE

smallintsmallint

SQL 数据类型在描述符的 TYPE 字段中显示的值。Value of the SQL data type as it appears in the TYPE field of the descriptor. 该列与 DATA_TYPE 列相同,datetime 和 SQL-92 interval 数据类型除外。This column is the same as the DATA_TYPE column, except for the datetime and SQL-92 interval data types. 该列始终返回值。This column always returns a value.

SQL_DATETIME_SUBSQL_DATETIME_SUB

smallintsmallint

datetime 及 SQL-92 interval 数据类型的子类型代码。Subtype code for datetime and SQL-92 interval data types. 对于其他数据类型,该列返回 NULL。For other data types, this column returns NULL.

CHAR_OCTET_LENGTHCHAR_OCTET_LENGTH

intint

列中的最大字节数。The maximum number of bytes in the column.

ORDINAL_POSITIONORDINAL_POSITION

intint

列在表中的索引。The index of the column within the table.

IS_NULLABLEIS_NULLABLE

字符串String

指示列是否允许 Null 值。Indicates if the column allows null values.

SS_IS_SPARSESS_IS_SPARSE

smallintsmallint

如果此列是稀疏列,它将具有值 1;否则为 0。1If the column is a sparse column, this has the value 1; otherwise, 0.1

SS_IS_COLUMN_SETSS_IS_COLUMN_SET

smallintsmallint

如果该列是稀疏 column_set 列,它将具有值 1;否则为 0。If the column is the sparse column_set column, this has the value 1; otherwise, 0. 11

SS_IS_COMPUTEDSS_IS_COMPUTED

smallintsmallint

指示 TABLE_TYPE 中的列是否为计算所得的列。Indicates if a column in a TABLE_TYPE is a computed column. 11

IS_AUTOINCREMENTIS_AUTOINCREMENT

字符串String

如果列是自动递增的,则为“是”。"YES" if the column is auto incremented. 如果列不是自动递增的,则为“否”。"NO" if the column is not auto incremented. 如果驱动程序无法确定列是否为自动递增,则为 ""(空字符串)。"" (empty string) if the driver cannot determine if the column is auto incremented. 11

SS_UDT_CATALOG_NAMESS_UDT_CATALOG_NAME

字符串String

包含用户定义类型 (UDT) 的目录名称。The name of the catalog that contains the user-defined type (UDT). 11

SS_UDT_SCHEMA_NAMESS_UDT_SCHEMA_NAME

字符串String

包含用户定义类型 (UDT) 的架构名称。The name of the schema that contains the user-defined type (UDT). 11

SS_UDT_ASSEMBLY_TYPE_NAMESS_UDT_ASSEMBLY_TYPE_NAME

字符串String

采用完全限定名称的用户定义类型 (UDT)。The fully-qualified name user-defined type (UDT). 11

SS_XML_SCHEMACOLLECTION_CATALOG_NAMESS_XML_SCHEMACOLLECTION_CATALOG_NAME

字符串String

在其中定义 XML 架构集合名称的目录的名称。The name of the catalog where an XML schema collection name is defined. 如果找不到目录名称,此变量则会包含一个空字符串。If the catalog name cannot be found, this variable contains an empty string. 11

SS_XML_SCHEMACOLLECTION_SCHEMA_NAMESS_XML_SCHEMACOLLECTION_SCHEMA_NAME

字符串String

在其中定义 XML 架构集合名称的架构的名称。The name of the schema where an XML schema collection name is defined. 如果找不到架构名称,则为空字符串。If the schema name cannot be found, this is an empty string. 11

SS_XML_SCHEMACOLLECTION_NAMESS_XML_SCHEMACOLLECTION_NAME

字符串String

XML 架构集合的名称。The name of an XML schema collection. 如果找不到名称,则为空字符串。If the name cannot be found, this is an empty string. 11

SS_DATA_TYPESS_DATA_TYPE

tinyinttinyint

扩展存储过程使用的 SQL ServerSQL Server 数据类型。The SQL ServerSQL Server data type that is used by extended stored procedures.

注意: 有关 SQL ServerSQL Server 返回的数据类型的详细信息,请参阅 SQL ServerSQL Server 联机丛书中的“数据类型 (Transact-SQL)”。Note For more information about the data types returned by SQL ServerSQL Server, see "Data Types (Transact-SQL)" in SQL ServerSQL Server Books Online.

(1) 如果正连接到 SQL Server 2005 (9.x)SQL Server 2005 (9.x),此列将不会出现。(1) This column will not be present if you are connecting to SQL Server 2005 (9.x)SQL Server 2005 (9.x).

备注

有关 getColumns 方法返回的数据的详细信息,请参阅 SQL ServerSQL Server 联机丛书中的“sp_columns (Transact-SQL)”。For more information about the data returned by the getColumns method, see "sp_columns (Transact-SQL)" in SQL ServerSQL Server Books Online.

在 MicrosoftMicrosoftSQL ServerSQL Server JDBC Driver 3.0 中,你将看到有别于以往 JDBC 驱动程序版本的以下行为更改:In the MicrosoftMicrosoftSQL ServerSQL Server JDBC Driver 3.0, you will see the following behavior changes from earlier versions of the JDBC Driver:

DATA_TYPE 列具有以下更改:The DATA_TYPE column has the following changes:

SQL ServerSQL Server 数据类型Data Type

JDBC Driver 2.0 中的返回类型(或者,如果连接到 SQL Server 2005 (9.x)SQL Server 2005 (9.x))和关联的数值常量Return Type in JDBC Driver 2.0 (or, if connected to SQL Server 2005 (9.x)SQL Server 2005 (9.x)) and Associated Numeric Constant

连接到 SQL Server 2008SQL Server 2008 或更高版本时 JDBC Driver 3.0 中的返回类型Return Type in JDBC Driver 3.0 when connected to SQL Server 2008SQL Server 2008 or later

大于 8 kB 的用户定义类型user-defined type larger than 8 kB

LONGVARBINARY (-4)LONGVARBINARY (-4)

VARBINARY (-3)VARBINARY (-3)

geographygeography

LONGVARBINARY (-4)LONGVARBINARY (-4)

VARBINARY (-3)VARBINARY (-3)

geometrygeometry

LONGVARBINARY (-4)LONGVARBINARY (-4)

VARBINARY (-3)VARBINARY (-3)

varbinary(max)varbinary(max)

LONGVARBINARY (-4)LONGVARBINARY (-4)

VARBINARY (-3)VARBINARY (-3)

nvarchar(max)nvarchar(max)

LONGVARCHAR (-1) 或 LONGNVARCHAR (JDBC 4) (-16)LONGVARCHAR (-1) or LONGNVARCHAR (JDBC 4) (-16)

VARCHAR (12) 或 NVARCHAR (JDBC 4) (-9)VARCHAR (12) or NVARCHAR (JDBC 4) (-9)

varchar(max)varchar(max)

LONGVARCHAR (-1)LONGVARCHAR (-1)

VARCHAR (12)VARCHAR (12)

timetime

VARCHAR (12) 或 NVARCHAR (JDBC 4) (-9)VARCHAR (12) or NVARCHAR (JDBC 4) (-9)

TIME (-154)TIME (-154)

datedate

VARCHAR (12) 或 NVARCHAR (JDBC 4) (-9)VARCHAR (12) or NVARCHAR (JDBC 4) (-9)

DATE (91)DATE (91)

datetime2datetime2

VARCHAR (12) 或 NVARCHAR (JDBC 4) (-9)VARCHAR (12) or NVARCHAR (JDBC 4) (-9)

TIMESTAMP (93)TIMESTAMP (93)

datetimeoffsetdatetimeoffset

VARCHAR (12) 或 NVARCHAR (JDBC 4) (-9)VARCHAR (12) or NVARCHAR (JDBC 4) (-9)

microsoft.sql.Types.DATETIMEOFFSET (-155)microsoft.sql.Types.DATETIMEOFFSET (-155)

COLUMN_SIZE 列具有以下更改:The COLUMN_SIZE column has the following changes:

SQL ServerSQL Server 数据类型Data Type

返回 JDBC Driver 2.0 中的类型Return Type in JDBC Driver 2.0

返回 JDBC Driver 3.0 中的类型Return Type in JDBC Driver 3.0

nvarchar(max)nvarchar(max)

10737418231073741823

2147483647(数据库元数据)2147483647 (database metadata)

xmlxml

10737418231073741823

2147483647(数据库元数据)2147483647 (database metadata)

小于或等于 8 kB 的用户定义类型user-defined type less than or equal to 8 kB

8 kB(结果集和参数元数据)8 kB (result set and parameter metadata)

存储过程返回的实际大小。Actual size returned by the stored procedure.

timetime

类型的字符串表示形式的字符长度,假定精度允许的最大值为秒的小数形式。The length in characters of the string representation of the type, assuming the maximum allowed precision of the fractional seconds' component.

datedate

与 time 相同same as time

datetime2datetime2

与 time 相同same as time

datetimeoffsetdatetimeoffset

与 time 相同same as time

BUFFER_LENGTH 列具有以下更改:The BUFFER_LENGTH column has the following change:

SQL ServerSQL Server 数据类型Data Type

返回 JDBC Driver 2.0 中的类型Return Type in JDBC Driver 2.0

返回 JDBC Driver 3.0 中的类型Return Type in JDBC Driver 3.0

大于 8 kB 的用户定义类型user-defined type larger than 8 kB

21474836472147483647

TYPE_NAME 列具有以下更改:The TYPE_NAME column has the following changes:

SQL ServerSQL Server 数据类型Data Type

返回 JDBC Driver 2.0 中的类型Return Type in JDBC Driver 2.0

返回 JDBC Driver 3.0 中的类型Return Type in JDBC Driver 3.0

varchar(max)varchar(max)

texttext

varcharvarchar

varbinary(max)varbinary(max)

imageimage

varbinaryvarbinary

DECIMAL_DIGITS 列具有以下更改:The DECIMAL_DIGITS column has the following changes:

SQL ServerSQL Server 类型Type

JDBC Driver 2.0JDBC Driver 2.0

JDBC Driver 3.0JDBC Driver 3.0

timetime

Nullnull

7(或指定的较小值)7 (or smaller if specified)

datedate

Nullnull

Nullnull

datetime2datetime2

Nullnull

7(或指定的较小值)7 (or smaller if specified)

datetimeoffsetdatetimeoffset

Nullnull

7(或指定的较小值)7 (or smaller if specified)

SQL_DATA_TYPE 列具有以下更改:The SQL_DATA_TYPE column has the following changes:

SQL ServerSQL Server 数据类型Data Type

JDBC Driver 2.0 中的 SQL ServerSQL Server 2008 数据值SQL ServerSQL Server 2008 Data Value in JDBC Driver 2.0

JDBC Driver 3.0 中的 SQL ServerSQL Server 2008 数据值SQL ServerSQL Server 2008 Data Value in JDBC Driver 3.0

varchar(max)varchar(max)

-10-10

-9-9

nvarchar(max)nvarchar(max)

-1-1

-9-9

xmlxml

-10-10

-152-152

小于或等于 8 kB 的用户定义类型user-defined type less than or equal to 8 kB

-3-3

-151-151

大于 8 kB 的用户定义类型user-defined type larger than 8 kB

在 JDBC Driver 2.0 中不可用Not available in JDBC Driver 2.0

-151-151

geographygeography

-4-4

-151-151

geometrygeometry

-4-4

-151-151

hierarchyidhierarchyid

-4-4

-151-151

timetime

-9-9

9292

datedate

-9-9

9191

datetime2datetime2

-9-9

9393

datetimeoffsetdatetimeoffset

-9-9

-155-155

示例Example

以下示例演示了如何使用 getColumns 方法返回 AdventureWorksAdventureWorks 示例数据库中的 Person.Contact 表的信息。The following example demonstrates how to use the getColumns method to return information for the Person.Contact table in the AdventureWorksAdventureWorks sample database.

import java.sql.*;

public class c1 {

public static void main(String[] args) {

String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks;integratedsecurity=true";

Connection con = null;

Statement stmt = null;

ResultSet rs = null;

try {

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

con = DriverManager.getConnection(connectionUrl);

DatabaseMetaData dbmd = con.getMetaData();

rs = dbmd.getColumns("AdventureWorks", "Person", "Contact", "FirstName");

ResultSet r = dbmd.getColumns(null, null, "Contact", null);

ResultSetMetaData rm = r.getMetaData();

int noofcols = rm.getColumnCount();

if (r.next())

for (int i = 0 ; i < noofcols ; i++ )

System.out.println(rm.getColumnName( i + 1 ) + ": \t\t" + r.getString( i + 1 ));

}

catch (Exception e) {}

finally {}

}

}

另请参阅See Also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值