This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jtable showing last record only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable showing last record only " Watch "Jtable showing last record only " New topic
Author

Jtable showing last record only

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
I have done my codeing and when i run it it shows only last record so please help my database code is this


My Gui code is this


Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Note from moderator:

We discussed the JDBC part of the code in this thread.
We advised Vivek to create a separate issue on this forum for the GUI part.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
years since I've done any db stuff, but your code seems to be mainly in the wrong order
(and not really a Swing problem)

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

True. I hadn't spotted the declaration within the for loop.

They are not both 0 based. ResultSet.getXXX() is 1 based.
So : record[i] = rs.getString(i+1);
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
You are saying that my Swing code is ok and in different thread of JDBC everyone is said that the code is ok so please tell me where is the problem than
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> You are saying that my Swing code is ok and in different thread of JDBC everyone is said that the code is ok so please tell me where is the problem than

No, I'm saying that it (possibly) looks like your code is in the wrong order
i.e. you have 2 lines inside the 'for loop' that should be outside of it,
1 line should precede, 1 line should follow.

I don't have your db stuff, so it's up to you to make the changes (see my first reply),
and test to see if they work. If not, post what happened (as in any differences to what you have now)
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Vivek Moyal wrote:You are saying that my Swing code is ok and in different thread of JDBC everyone is said that the code is ok so please tell me where is the problem than
That was me. Michael did a better job in finding the issues.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2156
    
    7


Well, the above looks like your code to create the TableModel. A I see it you are only adding a single "record" to the model and the value of "record" is the last row you read from the ResultSet.

To create a DefaultTableModel you need a Vector of Vectors. So you create a Vector as your main Vector. Then for every row in the ResultSet you create a new Vector and add the data from each column to it. So basically your code is correct expect instead of using an ArrayList of String[] you should be using a Vector of Vectors and then you can use that Vector directly to create the model.
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
If I use this code i got nothing


And if I use this code



I got this
[[Ljava.lang.String;@1bf216a]
[[Ljava.lang.String;@1bf216a, [Ljava.lang.String;@12ac982]
[[Ljava.lang.String;@1bf216a, [Ljava.lang.String;@12ac982, [Ljava.lang.String;@1389e4]
[[Ljava.lang.String;@1bf216a, [Ljava.lang.String;@12ac982, [Ljava.lang.String;@1389e4, [Ljava.lang.String;@c20e24]
[[Ljava.lang.String;@1bf216a, [Ljava.lang.String;@12ac982, [Ljava.lang.String;@1389e4, [Ljava.lang.String;@c20e24, [Ljava.lang.String;@2e7263]
[[Ljava.lang.String;@1bf216a, [Ljava.lang.String;@12ac982, [Ljava.lang.String;@1389e4, [Ljava.lang.String;@c20e24, [Ljava.lang.String;@2e7263, [Ljava.lang.String;@157f0dc]


At last if I use this code than i will get the last record

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

and if you use this ?

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Getting the whole record but one record is in one column and another is in another column record is whole but it is not distributed according to the columns
 
Consider Paul's rocket mass heater.
 
subject: Jtable showing last record only
 
Similar Threads
Need help in Connecting my MySQL Database to JTable in Eclipse.
JTable, Table Models, Vectors & Objects : Confused
class cast exception
JTable Dynamic - Urgent
Getting Last Record in Jtable