Here you can find the source of getPrimaryKeyColumn(DatabaseMetaData md, String TableName)
private static String getPrimaryKeyColumn(DatabaseMetaData md, String TableName) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.*; public class Main { private static String getPrimaryKeyColumn(DatabaseMetaData md, String TableName) throws SQLException { String PK_Col = null;/*from w w w . j a va 2s . c o m*/ ResultSet rs2 = md.getPrimaryKeys(null, null, TableName); while (rs2.next()) { String[] items = getResultSetStrings(rs2); if (PK_Col == null) { PK_Col = rs2.getString(4); } else { PK_Col = null; break; } } rs2.close(); return PK_Col; } public static String[] getResultSetStrings(ResultSet rs) throws SQLException { int nCols = getNumberColumns(rs); String[] ret = new String[nCols]; for (int i = 0; i < ret.length; i++) { ret[i] = rs.getString(i + 1); } return (ret); } public static int getNumberColumns(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int nCols = md.getColumnCount(); return (nCols); } }