*
The moose likes JDBC and the fly likes Getting Last Record in Jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting Last Record in Jtable" Watch "Getting Last Record in Jtable" New topic
Author

Getting Last Record in Jtable

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
I am getting last record only in the jtable my code is here


When i put this list in my table model


it shows the last record of the database

Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
Hi Vivek
Why do you think you are getting only the last record? And why not the first? Does this give a hint? Where and how are you collecting the records returned from the query?

Warm Regards
Jhakda


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Syed Ullah
Greenhorn

Joined: Mar 10, 2010
Posts: 9
You have declared record as an array of string, it is only able to store one row of the table, so it is getting re-written every time you are going through your result set. That is why you end up with the last record.

You need to declare a collection that will store items of record type. Something like:



Inside the loop where you go through the result set, you'll need to create a new record for each row of data and add it to the list:



Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Not getting the whole list just getting the last row and also getting records like that


[Ljava.lang.String;@1bf216a
[Ljava.lang.String;@12ac982
[Ljava.lang.String;@1389e4
[Ljava.lang.String;@c20e24
[Ljava.lang.String;@2e7263
[Ljava.lang.String;@157f0dc
[Ljava.lang.String;@863399
[Ljava.lang.String;@a59698
[Ljava.lang.String;@141d683
[Ljava.lang.String;@16a55fa
[Ljava.lang.String;@32c41a
[Ljava.lang.String;@e89b94
[Ljava.lang.String;@13e205f
[Ljava.lang.String;@1bf73fa
[Ljava.lang.String;@5740bb
[Ljava.lang.String;@5ac072
[Ljava.lang.String;@109a4c
[Ljava.lang.String;@201f9
[Ljava.lang.String;@1cf8583
[Ljava.lang.String;@14693c7
[Ljava.lang.String;@901887
[Ljava.lang.String;@3a6727
[Ljava.lang.String;@4a65e0
[Ljava.lang.String;@665753
[Ljava.lang.String;@ef22f8
[Ljava.lang.String;@1e0cf70
[Ljava.lang.String;@52fe85
[Ljava.lang.String;@c40c80
[Ljava.lang.String;@110d81b
[Ljava.lang.String;@dbe178
[Ljava.lang.String;@1af9e22
[Ljava.lang.String;@b6ece5
[Ljava.lang.String;@17ace8d
[Ljava.lang.String;@18eb9e6
[Ljava.lang.String;@14ed9ff
[Ljava.lang.String;@1ca318a
[Ljava.lang.String;@17a8913
[Ljava.lang.String;@1bd747e
[Ljava.lang.String;@12b3374
[Ljava.lang.String;@13f3789
[Ljava.lang.String;@1571886
[Ljava.lang.String;@10b4199
[Ljava.lang.String;@1ffb8dc
[Ljava.lang.String;@1c184f4
[Ljava.lang.String;@1ffbd68
[Ljava.lang.String;@ec16a4
[Ljava.lang.String;@1c29ab2
[Ljava.lang.String;@13a328f
[Ljava.lang.String;@1cd8669
[Ljava.lang.String;@337838
[Ljava.lang.String;@119cca4
[Ljava.lang.String;@ca2dce
[Ljava.lang.String;@18558d2
[Ljava.lang.String;@18a47e0
[Ljava.lang.String;@174cc1f
[Ljava.lang.String;@1050e1f
[Ljava.lang.String;@e24e2a
[Ljava.lang.String;@179c285
[Ljava.lang.String;@d1e604
[Ljava.lang.String;@54172f


I am new to Jtable its my first time so having difficulties now i have tried to get the list in ArrayList and Vector but still have the same problem
I am using Vector because it is directly accessible to DefaultTableModel.addRow()




Syed Ullah
Greenhorn

Joined: Mar 10, 2010
Posts: 9
I think you need to allocate memory for 'record' outside the 'for' loop.

Also, I am not sure if you can print an array of string like you are trying to do.
You may have to iterate over each element. That println should also be outside
the for loop.

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
[Ljava.lang.String;@1027b4d
[Ljava.lang.String;@1ed2ae8
[Ljava.lang.String;@19c26f5
[Ljava.lang.String;@c1b531
[Ljava.lang.String;@15eb0a9
[Ljava.lang.String;@1a05308



by using your example
Now i am getting only this and table is also showing this not the records
Syed Ullah
Greenhorn

Joined: Mar 10, 2010
Posts: 9
Write a function to print the record like this:

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Sir it will b good if you will write the code that how i will get the whole list in Jtable because i have to submit my assignment because right now i can't wait for more testing and disscussion
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Vivek Moyal wrote:Sir it will b good if you will write the code that how i will get the
whole list in Jtable because i have to submit my assignment because right now i can't wait for more testing and disscussion

Hi Vivek.

Please use real words. b is not a real word. i is upper case.
We will help you to find a solution. But we will *not* write code for you.
That is not how the JavaRanch works. Even if you don't have the time.




OCUP UML fundamental and ITIL foundation
youtube channel
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Sorry sir you take it in a wrong sence because if you see above than I have done with my code and still having the same problem so that at last I have said this I dont want to give you an order i just need your help to complete this because i have same problem what I have on the first day when I have created this topic

so if you want to see the code than you can see it above so now please help me
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Vivek Moyal wrote:Not getting the whole list just getting the last row and also getting records like that


[Ljava.lang.String;@1bf216a
[Ljava.lang.String;
...
...
[Ljava.lang.String;@54172f


I am new to Jtable its my first time so having difficulties now i have tried to get the list in ArrayList and Vector but still have the same problem
I am using Vector because it is directly accessible to DefaultTableModel.addRow()







Jumping back to this part of the thread. You were on the right track (I think). It seems that you have all the database rows in the Vector records.
But the print result is what you get if you print something of type String[ColCount].
But your JDBC part of the logic seems to be ok.

I can't help you with the GUI part going wrong. We have a 'Swing / AWT / SWT / JFace ' forum where you might get better help for that.


Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Shouln't 'Object record[]' be 'String[] record' ?
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
You are saying that my database code is ok and in different thread of swing everyone is said that the code is ok so please tell me where is the problem than
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

The other replier found an error in your code that I did not find.
He is right. He did a better job than me

For your column array, you declare your object in the for loop.
You should declare it before you step in the for loop:

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

... and, because Michael says you have to use Vecor in stead of Array for your GUI table:


(untested code, but you get the point)
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
I got the whole record but now the problem is this that one database row is in one column another is in another column

like this

FirstName LastName Address
Jhon,Doug Pheliipe,Marsh Katie,Price


Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Hello no ans from 3 days please help me in this application
 
Don't get me started about those stupid light bulbs.
 
subject: Getting Last Record in Jtable