Getting foreign key and refering table name of particular database table from metadata DatabaseMetaData using JAVA class

StackOverflow https://stackoverflow.com/questions/17169393

Pergunta

I am writing java class to get all connection database objects(tables). I have used

rs = meta.getExportedKeys(conn.getCatalog(), null, "account_adjustment");  

    while (rs.next()) { 
       String fkTableName = rs.getString("FKTABLE_NAME");
       String fkColumnName = rs.getString("FKCOLUMN_NAME");
       int fkSequence = rs.getInt("KEY_SEQ");      
     }

which is giving parent table and it's column linked this asked table(account_adjustment)

and also I tried

 rs1 = meta.getImportedKeys(conn.getCatalog(), null, "account_adjustment");
    while (rs1.next()) {
      String fkTableName = rs1.getString("FKTABLE_NAME");
      String fkColumnName = rs1.getString("FKCOLUMN_NAME");
    int fkSequence = rs1.getInt("KEY_SEQ");
    }

which is giving current table(account_adjustment) table and it's foreign key column name but I want table name with which this foreign key is linked

Foi útil?

Solução

I have got solution bt in other way not using java,, instead of getting values using java i executed query to 'information_schema' (which is there by default in MySQL) database and 'REFERENTIAL_CONSTRAINTS' table to get all reference of respective tables of required database

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top