Is there a JDBC method to get child tables and all of its descendants.
getExportedKeys returns only the direct child and not all its descendants. If I keep calling getExportedKeys() method recursively , it takes around 3 minutes for 50 tables or so (which is really slow)
Could someone please help me out for a solution.
Main objective is to avoid using queries since I would be dealing with different databases.
Recursive function used:
private static void getChildTables(DatabaseMetaData dbmd,Set<String> dependencies,String tableName,String schemaname ) throws SQLException{
ResultSet rs3 = dbmd.getExportedKeys(null,schemaname, tableName);
while (rs3.next()){
if(dependencies.contains(rs3.getString(7)))
continue;
dependencies.add(rs3.getString(7));
String childTable=rs3.getString(7);
getChildTables(dbmd, dependencies, childTable, null);
rs3.close();
rs3 = dbmd.getExportedKeys(null,schemaname, tableName);
}