#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    12
    Rep Power
    0

    How to get the tables created by me from the database


    Dear Friends,

    I have created a database called test. Now I have created some tables in the test. Now I want to retrieve the tables created by me using
    DatabaseMetaData.getTables(). If I put null for all the parameters then I get all the tables including some system tables.

    Kindly help me how to retrieve my own tables.

    regards,
    rajagopal
  2. #2
  3. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,156
    Rep Power
    24
    Assuming that's Java code in your post, you need to add some extra parameters to say what you're looking for. Namely, everything in the 'public' schema (i.e. stuff not created by the system), and what type of stuff you're looking for (tables.) Just put some extra parameters in there.

    // create your connection and store it in conn
    s = conn.createStatement();
    DatabaseMetaData meta = conn.getMetaData();

    String[] types = { "TABLE" };
    ResultSet rs = meta.getTables("your_db_name", "public", null, types);

    while (rs.next())
    System.out.println("Table: " + rs.getString("table_name"));


    If you wanted to get all of the sequences in a table (useful for when you restore a database and have to update sequence values):

    String[] types2 = { "SEQUENCE" };
    rs = meta.getTables("your_db_name", "public", null, types2);
    while (rs.next())
    System.out.println("Seq: " + rs.getString("table_name"));

    Hope this helps.
    Last edited by kurious; November 19th, 2003 at 09:57 AM.

IMN logo majestic logo threadwatch logo seochat tools logo