Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can you show data from a specific colum in a JList? through JDBC

 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI guys,

I have a table say, Staff and I want to show the surname colum in a JList.

Can any one tell me how can I do this.

after having my connection and PreStatment Object I tried the following Code. but could manage to do it.





The above code is okay and working, but when I try to show the LastName colume in a JList, it gives Error. the following code show how I am trying to Use JList with JDBC


The last two line goes inside a methode and could be called when an event is occured. I think the problems raise with the last two line as I am not sure about

Can any one please tell me, if there is a way to get it solved

thanks
Farhad

 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above code is okay and working, but when I try to show the LastName colume in a JList, it gives Error
What error? Compiler error? Runtime error?
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom

it's compile error.

I have tried the following code though



allStaff is a JList object

Regards
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the error. As I read the documentation the class JList does not have a method setListData() that accepts a List as a parameter.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Tom

I am using netbeans and Compile Error is shown with red underlined. I will tell you my story about this.

I have three classes

one for staff
one for all SQL queries
one for the GUI

I have a method (getAllPeople) in Queries Class and I have posted earliar. this method searchs for all and gets all the entries in the table which executes (Select * from Staff).
and it contains everything. forexample name, number, Id, salary, ................

I have created a JList instance in GUI class. now I call getAllPeople method with the following code which returns an ArrayList.

searchResult is an ArrayList or List.
Now I think all fields and columns are in the the list (e.g. Id, Name, surname, .............)
So, Now, how do you show only the Surname Column in JList?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic