aspose file tools*
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 Soft Skills this week in the Jobs Discussion 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: 2516
    
  10

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: 2516
    
  10

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: 2516
    
  10

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: 2225
    
    8


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: 2516
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable showing last record only