Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Using MySQL Table Names for Combo Box

Thread view: 
christopher_board@yahoo.co.uk - 14 Jun 2007 23:37 GMT
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.
wisccal@googlemail.com - 15 Jun 2007 11:51 GMT
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
[quoted text clipped - 4 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.