File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Populate JavaBean With Data Fetched From the Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Populate JavaBean With Data Fetched From the Database" Watch "Populate JavaBean With Data Fetched From the Database" New topic
Author

Populate JavaBean With Data Fetched From the Database

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Nov 27, 2001
Posts: 1561
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


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Dec 29, 2002
Posts: 1
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

Joined: Mar 19, 2002
Posts: 405
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populate JavaBean With Data Fetched From the Database