Get Database Table and View Names using JDBC
Return a List containing all Database Table (and View) Names using JDBC.
Javadoc available at https://www.javatapas.com/docs/javatapas/sql/GetDatabaseTableNames.html
public static List<String> getDatabaseTableNames(Connection conn) throws SQLException {
List<String> tableNames = new ArrayList<>();
DatabaseMetaData dmd = conn.getMetaData();
String schema = dmd.getUserName();
String[] dmdTypes = {"TABLE", "VIEW"};
ResultSet rset = dmd.getTables(null, schema, null, dmdTypes);
while (rset.next()){
String tableName = rset.getString(3);
tableNames.add(schema + "." + tableName);
}
rset.close();
return tableNames;
}