user323343
user323343

Reputation:

Putting sql result set into JList

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.

Upvotes: 2

Views: 2067

Answers (1)

Marcin
Marcin

Reputation: 7994

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.

Upvotes: 4

Related Questions