Here you can find the source of getPrimaryKeys(Connection conn, String tableName)
public static List<String> getPrimaryKeys(Connection conn, String tableName) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getPrimaryKeys(Connection conn, String tableName) throws SQLException { ResultSet rs = null;/*w ww . ja v a 2 s . c o m*/ try { List<String> pkNames = new ArrayList<String>(); //get pk name DatabaseMetaData dbMeta = conn.getMetaData(); rs = dbMeta.getPrimaryKeys(null, null, tableName.toUpperCase()); while (rs.next()) { pkNames.add(rs.getString("COLUMN_NAME")); } return pkNames; } finally { try { rs.close(); } catch (Exception e) { } } } }