• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable showing last record only

 
Vivek Moyal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and if you use this ?

 
Vivek Moyal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic