Using MySQL Table Names for Combo Box

Discussion in 'Java' started by christopher_board@yahoo.co.uk, Jun 14, 2007.

  1. Guest

    Hi all. I am trying to write a program where it has to connect to a
    MySQL Database. Within the program there will be a drop down box that
    will show class room names. In the datbase there is going to be a
    table for each class room. I would like to add every table name within
    a datbase into the drop down box if the java program. How would I go
    about doing this.

    Any help would be appreciated in this matter.
    , Jun 14, 2007
    #1
    1. Advertising

  2. Guest

    On Jun 14, 6:37 pm, wrote:
    > Hi all. I am trying to write a program where it has to connect to a
    > MySQL Database. Within the program there will be a drop down box that
    > will show class room names. In the datbase there is going to be a
    > table for each class room. I would like to add every table name within
    > a datbase into the drop down box if the java program. How would I go
    > about doing this.
    >
    > Any help would be appreciated in this matter.



    How about something like this?

    try {
    Connection con = getConnection(); //Get you Connection object
    DatabaseMetaData meta = con.getMetaData();
    ResultSet rs = meta.getTables(null, null, "%", new String[]
    {"Table"}); //Get only tables (no views, etc). You can adjust the 3rd
    parameter to match only certain names.

    while(rs.next()) {
    String table = rs.getString(3);
    System.out.println(table);
    }
    con.close();
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    }

    Regards,
    Steve
    ------------------
    www.stkomp.com
    , Jun 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5nZWw=?=

    COMBO BOX INSTEAD OF DROP DOWN BOX

    =?Utf-8?B?QW5nZWw=?=, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    609
    Ken Cox [Microsoft MVP]
    Jun 29, 2004
  2. Adrian
    Replies:
    1
    Views:
    218
    Bullschmidt
    Feb 18, 2004
  3. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    587
    Bob Barrows [MVP]
    Nov 16, 2005
  4. Mike

    Combo Box and text box

    Mike, Sep 24, 2003, in forum: Javascript
    Replies:
    2
    Views:
    157
  5. SM
    Replies:
    2
    Views:
    364
Loading...

Share This Page