aspose file tools*
The moose likes JDBC and the fly likes Database issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database issues" Watch "Database issues" New topic

Database issues

Andre Jonn

Joined: Aug 23, 2012
Posts: 6
hello my people.I'm new here and i need help.can someone show me an example on how to retrieve database tables and add them as items to a jcombobox?i really need help in that aspect.
Secondly,how can i get a column name in a java gui app?

like i dont know if this is correct:

please i need serious help.i actually have a little sql knowledge but i dont know how to do this in a gui app.Thanks
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 39788
Welcome to the Ranch

I suggest you look at the Java Tutorials, which has a useful section about JDBC.
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
Connection con = DriverManager.getConnection(url,properties);
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs=dbmd.getTables(null, null, null, new String[] { "TABLE" });
Andre Jonn

Joined: Aug 23, 2012
Posts: 6
@Wei: Thanks man.please can you give me a full code on that part because you stopped at the ResultSet how do i finish it up?
Please since you have started,help me with the finish i'd appreciate it.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19759

We are NotACodeMill. You can loop over the ResultSet yourself and check out what it returns. The Javadoc of the getTables method also describes the columns of the result set.

How To Ask Questions How To Answer Questions
Andre Jonn

Joined: Aug 23, 2012
Posts: 6
@Rob Spoor: I'm not saying that you guys are code a code a mill whatever you call it.All i ask is just a little more help since i'm doing this for the first time.if Wei can just help me with the rest of the code like the area where i can add the results of the ResultSet into my jcombo box as items,it will make me feel want me to learn don't you?
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3611

Andre, Campbell has given you a link to the JDBC tutorial, which is an excellent learning resource with lots of code samples. A sample code of using a ResultSet is actually just three clicks from there, though I don't think jumping right on it is the best way to learn.

Furthermore, you should separate the two issues, that is reading data from the database, and populating the combobox. They are really different problems. In good code, JDBC and Swing never go together. If you are new to Swing as well, the best anyone can do for you is to give you link to the Swing tutorial.

Please read these tutorials and if you don't understand something, feel free to come back here and ask specific questions (if it's going to be about Swing, please ask in the Swing forum).

We very much want you to learn. The tutorials are excellent resources, created by Sun and now maintained by Oracle. These tutorials are much better way of learning than staring at random snippets of code, since they include the why, not only the how.
I agree. Here's the link:
subject: Database issues