Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created May 28, 2010 19:25
Show Gist options
  • Save duncanmak/417608 to your computer and use it in GitHub Desktop.
Save duncanmak/417608 to your computer and use it in GitHub Desktop.
//find PK column
List<String> pkColList = new ArrayList<String>();
DatabaseMetaData dbMetaData = con.getMetaData();
ResultSet pkRs = dbMetaData.getPrimaryKeys(null, schema, table);
while(pkRs.next()) {
pkColList.add(pkRs.getString(4));
}
pkRs.close();
if (pkColList.size() != 1) {
throw new InvalidTableException("Table " + schema + "." + table + " has " + pkColList.size() + " PK columns - only allowed 1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment