I have a JTable with a default table model which I am using to display a result set. I am using postgreSQL. I am trying to get the table to exclude Primary and foreign keys. So far I have gotten it to exclude the primary keys but I have been unsuccessful in excluding the foreign keys.
This is how I am getting the foreign keys:
public List<String> getFKeyData(String tableName, int i) throws SQLException {
DatabaseMetaData dm = connection.getMetaData();
ResultSet rs = dm.getImportedKeys(null, null, tableName);
ArrayList<String> fkTableData = new ArrayList<>();
while (rs.next()) {
fkTableData.add(rs.getString(i));
}
return fkTableData;
}
This is how I initially thought to exclude the foreign keys:
int fkSize = databaseConnection.getFKeyData(tableName, 8).size();
for (int i = 0; i <= fkSize - 1; i++) {
if (databaseConnection.getColumnNames(tableName).indexOf(databaseConnection.getFKeyData(tableName, 8).get(i)) == 1) {
if (databaseConnection.getColumnNames(tableName).indexOf(databaseConnection.getPKey(tableName)) != 1) {
if (databaseConnection.getColCount(tableName) >= 1) {
model.addColumn(columnNamesV.get(1), cellData1);
}
}
}
}
I now realize this was foolish because although it does exclude the foreign key it is added to the model anyway by the for statement. Does anyone know a way around this?