• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database issues

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I suggest you look at the Java Tutorials, which has a useful section about JDBC.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic