• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set mysql result set into JTable

 
Skm Liyanage
Greenhorn
Posts: 23
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have database called details. It has table called persons. persons have name, telePhoneNum, Address fields. So i want to represent this persons table in a jTable which is JFrame. I cannot understand that. I searched in google whole night.but no one is as i understand. Please hellp me?
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's too big a question. You have to break it down into smaller steps. What you want to do first is create a connection to your database in Java code, run a query, and get a result set. Are you able to do that part?
 
Skm Liyanage
Greenhorn
Posts: 23
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much.
Yes i can connect. Connection code segment is ok. i got result set by SELECT * FROM persons;
now my question is how to this result set put on a jtable?
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In pseudo code
1) Define Person object .
2) Provided instance variables for all the values you want to map from the DB
3)Prepare and fire the db query
4) Iterate the result set. For each iteration, create a new Person instance in #1 above and populate with values from result set
5) Add each person instance to a collection (e.g. List)
6) Define your table model. Pass this list as the seed data.
Number of rows in the model = number of person objects in list
Number of columns = number of values you want to display on the table
Column names = attribute names (e.g. name address etc)
Row data = values from each person object
7) Create a JTable from this model and display on the UI

Recommended reading for 6 & 7 http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
Skm Liyanage
Greenhorn
Posts: 23
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much my friend.
Still i cannot do this.
I created following code segment to get result set.


so i can get result set by calling to this view method. And also, i have created another class called "ViewALL". it has only a jTable.
So, now want to set that result set on this jtable. plese help me.
If you give me suitable code segment for this it will be more helpful me.
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, now want to set that result set on this jtable. plese help me.
If you give me suitable code segment for this it will be more helpful me.

Help will be given at the Ranch to those who ShowSomeEffort We do not just hand out ready made code.

I have already outlined the way which you can do it. Your code snippet just does #3
 
Skm Liyanage
Greenhorn
Posts: 23
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnk you vety much my friend. if it is trouble to you very sory.
I may be unlucky one today. I try to do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic