views:

253

answers:

1

Hi there.

I'm working on my second year project and I'm nearly finished, but I've got a problem.

I have a table set up in Oracle that holds user names, recipients, and messages.

I wanted to make a contacts list for sending messages that would take the user names and put them into a swing jlist but i cant figure out how.

I thought maybe if I put the usernames into an array from the SQL it'd be easier but that didn't work. Any ideas?


Just to update, I already connected to the database.

+3  A: 

First, you need to connect to a database, then read data from it, then massage the result into JList.

To connect to oracle from Java you need to use JDBC, tutorial for which is conveniently located here: http://java.sun.com/docs/books/tutorial/jdbc/index.html.

Then once you have the data, you need to put this into a JList, which has setListData method, which will do all the magic. While iterating over the data from JDBC you just need to make sure you're putting the output of your SQL query into a Vector, documented here: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html.

Marcin
never heard of the setlist data method but it sounds ike its what i need. gonna check now. ive already conected to the database and created the Jlist.never used vectores before. i would paste some code to view but theres way too much
0vertone
sorry vectors just arent workin for me. its gotten even more complicated now.
0vertone
You could use a List instead, such as an ArrayList - which follows the Collections framework and is sometimes easier for people to understand.
aperkins
@aperkins that sounds much more doable. arrays i get.i dont get why this is giving me so much trouble. all i want is a simple list of strings from an sql table. now its spaghettti :S
0vertone
@0vertone: ArrayList and Vector are effectively the same thing (although Vector is thread safe, unlike ArrayList). The Collections framework is designed to be used with collections of things - and to make the ideas of array lists, linked lists, sets maps and the like to be easily accessible within the Java framework.
aperkins