• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieve complete rows of table using jsp and servlet  RSS feed

 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one table in mysql in that some rows are there i want to retrieve all rows using servlet and jsp concept and i have done half of the way but not getting output it is
showing some info and nothing getting printed on page except columns heading and here is my bean class..

and here is my servlet code




and here is my jsp code



please anyone help me....
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all the records you expect being returned to the servlet? Since you iterate over them, it's real easy to count and check. You may also want to add some logging code.
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i am new to this thing please tell me what should i do... and what syntax i need to use to get the values in servlet itself...

it is... items.getInTime(); ...........?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could start by this:

Then you would know if you're even getting the values from the DB that you think you're getting. Before you know that, you're just guessing what might be going wrong, and that's likely a waste of time.
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sir i am getting and it is showing---> records retrieved from the DB: 2
and in database only two rows are there in that particular table now please tell me next step
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how many <tr> elements are being created in the HTML page?

One problem I notice is that you're only creating a single instance of TimeDetailBean - so you will only ever get details of a single record, namely the very last one. You should create a TimeDetailBean instance for each DB record.
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir thanks for your attention you are right when i am using this code in jsp <td>${item.getDate()}</td> like this then i was getting only last row and it was retrieving 2 times means no of time was coming according to availability of no of rows and 4 fields are there in database so i have created 4 <td> so i can retrieve them and tell me how to create TimeDetailBean instance for each DB record i mean syntax .... i am working on this from 2 days not getting sol... please sir...
 
sreenu valireddi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove


TimeDetailBean e = new TimeDetailBean();

and do as follows



while (rs.next())
{
TimeDetailBean e = new TimeDetailBean();
e.setDate(rs.getDate(1));
e.setInTime(rs.getTime(2));
e.setOutTime(rs.getTime(3));
e.setEid(rs.getString(4));

items.add(e);


}
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnks sir i will try this and will tell thanks looot sir...




 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir its working its solved............thanks loooooooooooooooot , i am very happy...actually i tried this also before but i have done some syntax error there....but now its fine.... thank you sir so much... i have one more issue like same problem only but it is related to xml i will post that by tomorrow..... please help me in that also..once again thank you its solved..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!