code: 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;
      }
docs: Returns a table's primary key columns as a Set of strings.