I am trying to get all db tables using DatabaseMetaData.getTables() method. But this method requires database schema name pattern. Is it possible to get schema name for current db connection?
I am trying to get all db tables using DatabaseMetaData.getTables() method. But this method
Share
The standard schema for your current connection is the name of the user you use to log in. So if your user is
SCOTTyou have to useSCOTTforDatabaseMetaData.getTables().You can obtain the username through
DatabaseMetaData.getUserName().But remember that the comparison of schema/username done in the JDBC driver is case-sensititve and normally usernames are in uppercase.
I am not 100% sure if
DatabaseMetaData.getUserName()will return the name in the correct case in all situations. To be sure, you might want to do an upperCase() before using that value.