0

I have created a program to fetch all the table names from the user rt using DatabaseMetaData, although the program is compiled successfully and running it is not fetching the table names. It runs and displays list of tables: and then no names. Program exits.

Could anyone here please help me to find the wrong logic in my program.

//DataBaseMetaDataTest
import java.sql.*;
class DatabaseMetaDataTest
{
    public static void main(String s[])
    {
        try
        {
            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","rt","pwdd");
            DatabaseMetaData dbmd=con.getMetaData();
            ResultSet rs=dbmd.getTables(null,"rt",null,new String[]{"Table"});
            System.out.println("list of tables:");
            while(rs.next())
            {
                System.out.println(rs.getString(3));
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
Vikalp
  • 1
  • 5
  • i think you can get the metadata only from the specified table with the DatabaseMetaData( http://www.java2s.com/Code/JavaAPI/java.sql/ResultSetgetMetaData.htm) – Thomas Jul 18 '16 at 13:07
  • why dont you use the all_tables system table ("dictionary")? – Thomas Jul 18 '16 at 13:08

1 Answers1

0

In Oracle schema (=user) names are stored in upper case, so you also need to pass the schema name in upper case in the JDBC call.

I think you also need to pass the type list in upper case as well.

dbmd.getTables(null,"RT",null,new String[]{"TABLE"});