0

I am practicing JDBC and trying to get the list of table names and view names with the help of DatabaseMetaData interface.

Here is a sample code:

public class Sample {

    public static void main(String[] args) throws SQLException {
        try(Connection con = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:xe", "test",
                "test")){
            DatabaseMetaData dbmd = con.getMetaData();
            ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"});

            while(rs.next()){
                System.out.println(rs.getString(1));
                System.out.println(rs.getString(2));
                System.out.println(rs.getString(3));
                System.out.println(rs.getString(4));
            }
        }
    }

} 

I was just trying to get the tables which are available for the login user "test" which I was using for creating DB connection, but in the output I am seeing so many records, so how I just get the table names and view names?

learner
  • 6,062
  • 14
  • 79
  • 139
  • relevant: http://stackoverflow.com/questions/2780284/how-to-get-all-table-names-from-a-database – user432 Aug 06 '15 at 15:12
  • IIRC a lot of drivers won't restrict the tables to those accessible to the current user (unless the databases metadata tables do that themselves). – Mark Rotteveel Aug 06 '15 at 20:54

0 Answers0