Injecting sql result set into JList
I am working on a second project and I am almost done, but I have a problem.
I have a table set up in Oracle that contains usernames, recipients and messages.
I wanted to create a posting contact list that will take usernames and put them in a swing jlist, but I can't figure out how.
I thought maybe if I put the usernames into an array from SQL it would be easier, but it didn't work. Any ideas?
Just to update I have already connected to the database.
First you need to connect to the database, then read data from it, and then mass the result into a JList.
To connect to oracle from Java you need to use JDBC, a tutorial conveniently located here: http://java.sun.com/docs/books/tutorial/jdbc/index.html .
Then, once you have the data, you have to put it in JList
, which has a method setListData
that will do all the magic. When iterating over data from JDBC, you just need to make sure you put the output of your SQL query in the Vector
one described here: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html ...
a source to share