• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Last Record in Jtable

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a function to print the record like this:

 
Vivek Moyal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



 
Vivek Moyal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouln't 'Object record[]' be 'String[] record' ?
 
Vivek Moyal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... 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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello no ans from 3 days please help me in this application
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic