• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database issues

 
Andre Jonn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I suggest you look at the Java Tutorials, which has a useful section about JDBC.
 
Wei Dai
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection con = DriverManager.getConnection(url,properties);
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs=dbmd.getTables(null, null, null, new String[] { "TABLE" });
 
Andre Jonn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Wei: Thanks man.please can you give me a full code on that part because you stopped at the ResultSet part.now how do i finish it up?
Please since you have started,help me with the finish i'd appreciate it.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andre Jonn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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 better.you want me to learn don't you?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic