Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populate JavaBean With Data Fetched From the Database

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean. There are three field variables in the bean; username, userrole, and category. "username" is supplied by me. "userrole" and "category" in the bean gets populated by fetching data from the database. I am positive that data are present in the database. However, I got "blanks" when I later on tried to display the properties (userrole and category) of that bean. I would appreciate if anybody could help identifying the problem. The relevant codes are show below:

My data access code is show below:

[ November 28, 2003: Message edited by: JiaPei Jen ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anything wrong with your code (quick look though). What I recommend is to print to the log the values you get from the DB

doing that you ensure that you're getting something from the DB, and not empty or null.
hope it helps
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data table is created by me. I am positive that every field in the table has a value for every single record.
In my JSP, I am able to display the value of "username". It means that the session object can be found. The JSP does not display anything (it is blank) for "userrole" and "category".
 
Gazi Peer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check to see whether the fieldnames of your jsp page are one and the same as in the properties of the java bean.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. I would check and verify that your jsp/property attributeS are in synch with your get/set methods of your bean.
For example, I noticed that that the following methods are different. Because the
getc[atagory is not the same as the setCategory:

Check that with your jsp page.
Craig
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic