Tome un vistazo a SchemaCrawler (libre y de código abierto), que es otra API diseñado para este propósito. Parte del código SchemaCrawler muestra:
// Create the options
final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
// Set what details are required in the schema - this affects the
// time taken to crawl the schema
options.setSchemaInfoLevel(SchemaInfoLevel.standard());
options.setShowStoredProcedures(false);
// Sorting options
options.setAlphabeticalSortForTableColumns(true);
// Get the schema definition
// (the database connection is managed outside of this code snippet)
final Database database = SchemaCrawlerUtility.getDatabase(connection, options);
for (final Catalog catalog: database.getCatalogs())
{
for (final Schema schema: catalog.getSchemas())
{
System.out.println(schema);
for (final Table table: schema.getTables())
{
System.out.print("o--> " + table);
if (table instanceof View)
{
System.out.println(" (VIEW)");
}
else
{
System.out.println();
}
for (final Column column: table.getColumns())
{
System.out.println(" o--> " + column + " (" + column.getType()
+ ")");
}
}
}
}
http://schemacrawler.sourceforge.net/
¿Es necesario cerrar la conexión sí mismo o hace el método() getDatabase hace eso para usted? –
@AndrewSwan - SchemaCrawler no cerrará la conexión por usted. Debe cerrarlo usted mismo. –
En ese caso, ¿le gustaría actualizar su ejemplo para que cierre la conexión en un bloque finally? –