1 package net.sourceforge.addam.util; 2 3 4 import java.util.List; 5 import java.util.ArrayList; 6 import java.sql.Connection; 7 import java.sql.DatabaseMetaData; 8 import java.sql.ResultSet; 9 import java.sql.SQLException; 10 11 import net.sourceforge.addam.ddlgen.GeneratorSpec; 12 13 /** 14 * Created by IntelliJ IDEA. 15 * User: TIM3 16 * Date: Oct 27, 2006 17 * Time: 11:59:34 PM 18 * To change this template use File | Settings | File Templates. 19 */ 20 public class DatabaseMetaDataUtil { 21 22 public static List<String> getTables(String catalog, String schema, Connection connection) throws SQLException { 23 24 DatabaseMetaData metadata = connection.getMetaData(); 25 if (metadata.storesUpperCaseIdentifiers()) { 26 catalog = (catalog == null) ? null : catalog.toUpperCase(); 27 schema = (schema == null) ? null : schema.toUpperCase(); 28 } else if (metadata.storesLowerCaseIdentifiers()) { 29 catalog = (catalog == null) ? null : catalog.toLowerCase(); 30 schema = (schema == null) ? null : schema.toLowerCase(); 31 } 32 ResultSet tablesRS = metadata.getTables(catalog, schema, "%", new String[]{"TABLE"}); 33 List<String> objects = new ArrayList<String>(); 34 while (tablesRS.next()) { 35 String dbObject = tablesRS.getString(3); 36 objects.add(dbObject); 37 } 38 return objects; 39 } 40 41 }