Using MySQL Table Names for Combo Box

C

christopher_board

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.
 
W

wisccal

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top