views:

208

answers:

3

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.

+2  A: 

You're always free to get java.sql.DatabaseMetaData using the Connection. There aren't any methods in SimpleJdbcTemplate to help you, but frankly there's no need. Just follow this recipe.

duffymo
It's possible that the spring aspect is important due to transaction manager interactions or something.
bmargulies
I wouldn't think transactions are needed for a read-only operation like this. The only problem could be if someone changes the schema while you're performing the operation in such a way that the result is invalidated. If that can happen, you've got far bigger issues.
duffymo
+1  A: 

Query the USER_TABLES view and you will get them.

poke around in sqlplus, of course, to see the shape first.

bmargulies
In my experience, the application's "tables" are often synonyms to tables in another schema, so you may have to query ALL_TABLES also.
Dan
+4  A: 

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.

Jason Gritman
+1 from me - this is the best answer by far. Nice.
duffymo