Jetez un oeil à SchemaCrawler (source libre et ouvert), qui est une autre API conçue à cet effet. Certains exemples de code de SchemaCrawler:
// 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/
Avez-vous besoin de fermer la connexion ou vous ne la méthode getDatabase() font cela pour vous? –
@AndrewSwan - SchemaCrawler ne ferme pas la connexion pour vous. Vous devez le fermer vous-même. –
Dans ce cas, vous pouvez mettre à jour votre exemple afin qu'il ferme la connexion dans un bloc finally? –