niran niran - 1 year ago 61
Java Question

Get list of all table names from spring SimpleJdbcTemplate

Is there a way to obtain the list of all table names in the database using Spring's SimpleJdbcTemplate?

The database being queried is Oracle if that helps in any way. Thanks.

Answer Source

Spring has a DatabaseMetaDataCallback object that can take care of some of the boiler plate aspects of the solution that duffymo has linked to. You can then pass that object when calling JDBCUtils.extractDatabaseMetaData.

An example of making the same call you're trying to make with those classes can be found here.

Sample code from that link:


class GetTableNames implements DatabaseMetaDataCallback {

        public Object processMetaData(DatabaseMetaData dbmd) throws SQLException {
            ResultSet rs = dbmd.getTables(dbmd.getUserName(), null, null, new String[]{"TABLE"});
            ArrayList l = new ArrayList();
            while ( {
            return l;


GetTableNames getTableNames = new GetTableNames();
try {
    Object o = JdbcUtils.extractDatabaseMetaData(dataSource, getTableNames);
} catch (MetaDataAccessException e) {