Ejemplo n.º 1
0
  private String getPrimaryKey(
      DatabaseMetaData meta, String dbName, String schema, String tableName) throws SQLException {
    String pKey = null;
    ResultSet resultSet = meta.getPrimaryKeys(dbName, schema, tableName);

    if (resultSet.next()) {
      resultSet = meta.getPrimaryKeys(dbName, schema, tableName);
    } else {
      resultSet = meta.getPrimaryKeys(null, schema, tableName);
    }
    while (resultSet.next()) {
      pKey = resultSet.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
      return pKey;
    }
    return pKey;
  }
Ejemplo n.º 2
0
 /** 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;
 }