Here you can find the source of getPrimaryKey(DatabaseMetaData metadata, String tableName)
public static Set<String> getPrimaryKey(DatabaseMetaData metadata, String tableName) throws Exception
//package com.java2s; //License from project: Open Source License import java.util.*; import java.sql.*; public class Main { private static final int PRIMARY_PK_COL_NAME = 4; /**//w w w .ja va2 s . com * Returns a table's primary key columns as a Set of strings. */ public static Set<String> getPrimaryKey(DatabaseMetaData metadata, String tableName) throws Exception { Set<String> columns = new HashSet<String>(); ResultSet keys = metadata.getPrimaryKeys(metadata.getConnection().getCatalog(), metadata.getUserName(), tableName); while (keys.next()) { columns.add(keys.getString(PRIMARY_PK_COL_NAME)); } keys.close(); return columns; } }