getPrimaryKeys Method (SQLServerDatabaseMetaData)
Retrieves a description of the primary key columns of the given table.
public java.sql.ResultSet getPrimaryKeys(java.lang.String cat,
java.lang.String schema,
java.lang.String table)
매개 변수
cat
A String that contains the catalog name.
schema
A String that contains the schema name.
table
A String that contains the table name.
반환 값
A SQLServerResultSet object.
예외
주의
This getPrimaryKeys method is specified by the getPrimaryKeys method in the java.sql.DatabaseMetaData interface.
The result set returned by the getPrimaryKeys method will contain the following information:
Name | Type | Description |
---|---|---|
TABLE_CAT |
String |
The name of the database in which the specified table resides. |
TABLE_SCHEM |
String |
The schema for the table. |
TABLE_NAME |
String |
The name of the table. |
COLUMN_NAME |
String |
The name of the column. |
KEY_SEQ |
short |
The sequence number of the column in a multicolumn primary key. |
PK_NAME |
String |
The name of the primary key. |
참고
For more information about the data returned by the getPrimaryKeys method, see "sp_pkeys (Transact-SQL)" in SQL Server Books Online.
예
The following example demonstrates how to use the getPrimaryKeys method to return information about the primary keys of the Person.Contact table in the SQL Server 2005 AdventureWorks sample database.
public static void executeGetPrimaryKeys(Connection con) {
try {
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys("AdventureWorks", "Person", "Contact");
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();
}
}
참고 항목
참조
SQLServerDatabaseMetaData Class
개념
SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members