Hi folks ,
Im developing a web app where im trying to pass the value of a list from the database through a DAO class onto a servlet which displays it in a jsp when called , however im not being able to call the function which generates the List in the servlet as a result a null List is returned .any ideas why this is happening ?
My servlet class generating the list.
Thanks in advance
Learning and Learning!-- Java all the way!
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
Hi,
Did you try printing the contents of the "domList" in the servlet?
It's not obvious to me why you need the method setDomList() since you always create a new list in the getDomList(). Also, why does domList need to be an instance variable?
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
Hello,
What does this print ?
System.out.println("The size of domList is"+domList.size());
James Sabre wrote:It's not obvious to me why you need the method setDomList() since you always create a new list in the getDomList(). Also, why does domList need to be an instance variable?
Well I was using domList as a bean instance variable and hence the getter and setters.I wanted to access it in my jsp through a bean.
And for amit's q.. thats not being printed , I guess the control never reaches that statement
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
Yeah.
You debug that thing and you should be fine after fix.
amit punekar wrote:Yeah.
You debug that thing and you should be fine after fix.
Regards,
Amit
Im trying to figure out how to debug here , any help would be appreciated. THE DAO object"DataObject ' is created and called , thats pretty starightforward. Ive inserted logging pretty much everywhere i could be going wrong, checked the DB however the List is still empty
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
Hello,
I can think of two things here -
1) Check if the query that is printed from your program if it returns you any results.
2) If yes then then check your DB connection details to confirm if you are connecting to the same database on which you ran the query #1.
I also have a question about your the following Servlet code
Did you mean to do the following?
It seemed weird that you were trying to set the domainType of a variable that is not show where it is declared or what it does. It is also strange that you change its value after you send the request dispatch forward.
It seemed weird that you were trying to set the domainType of a variable that is not show where it is declared or what it does. It is also strange that you change its value after you send the request dispatch forward.
Well Mike,
I wouldnt be able to directly implement your code snippet as I cannot access the setDomainType_Oid through DataObject as SetDomainType_Oid is setter method of the instance variable bean , so i would need to do something like
DataObject.bean.setDomainType_Oid(domainType_Oid);
which is syntatically wrong . Any ideas on how I could go about doing it?
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
Hi,
All Mike is trying to point out possible error in the way you are calling the function setXXX() and not syntactically.
You seems to be using "domainType_Oid" as part of string concatenation in your SQL. If this is true then shouldn't you be setting this value before you invoke "getDomList()" which uses this value as mentioned above.
Have you verified any of the following:
domainType_Oid is not equals to 0 or negative one
Are you successfully connecting to the database
Did the query return any value?
I think your problem is that you are not setting the domainType_Oid variable (it explains why you are receiving a NullPointerException). Can you add some debug to print the value of domainType_Oid to the system log before the first if statement?
hi Mike and Amit,
Thank you for your replies. Iwill try to explain where i could be going wrong here..
amit punekar wrote:Hi,
All Mike is trying to point out possible error in the way you are calling the function setXXX() and not syntactically.
You seems to be using "domainType_Oid" as part of string concatenation in your SQL. If this is true then shouldn't you be setting this value before you invoke "getDomList()" which uses this value as mentioned above.
Regards,
Amit
I didnt quite understand this.
Mike Zal wrote:Have you verified any of the following:
domainType_Oid is not equals to 0 or negative one
Are you successfully connecting to the database
Did the query return any value?
I think your problem is that you are not setting the domainType_Oid variable (it explains why you are receiving a NullPointerException). Can you add some debug to print the value of domainType_Oid to the system log before the first if statement?
Well , I did the check for domaintype_oid in my DAO class , however that code is not executed . I do know that im being able to connect to the database .Because I populate a drop down in my jsp through a dynamic list from the database.But As far as getting this list goes it returns only a NULL , im not being able to figure out why , imo its not even reaching the DB code ,ie. DAO class.
Awaiting your replies.
Vic, could you please post exactly which debug statements are being printed and which ones are not being printed. After reading your posts, it seems like you are seeing the following debug
After the echoed query there is no other output. Is this correct?
Not really since none of the debug you printed seems to match what is inside the getDomList() method. Either your System.out.print statements are printing somewhere else or the code is never being executed. Can you try making a small change to your code and see if you see any of the new debug.
Mike Zal wrote:Not really since none of the debug you printed seems to match what is inside the getDomList() method. Either your System.out.print statements are printing somewhere else or the code is never being executed. Can you try making a small change to your code and see if you see any of the new debug.
Yep you'd guessed right.The domList is set to null
Heres the debug code..Please help on how I could get it to work
Since "Skipped All Processing in DataObject class" appeared in your debug, it means that domainType_Oid equals 0 or -1. You need to set that variable after you instantiate the DataObject but before you call getDomList().
Hi Mike,
You were right . The value of Domaintypeoid is being set to zero(checked by logging) . The thing is im being able to retrieve the required value of domaintypeoid in my servlet , how do I pass the same value to my DAO class , so that i can set the value of domaintype-oid before the if loop is executed?
In the Servlet, you could set the DAO object as a request attribute. In your JSP, you could just use the request.getAttribute instead of instantiating a new DAO object.
rav pad
Greenhorn
Joined: Jun 07, 2011
Posts: 3
posted
0
Vic,
Can you suppply the log of the whole thing starting from the first if
if(domainType_Oid!=0 && domainType_Oid!=-1){} because I see that the log which you have already supplied does not match with the System.Out.Println given in the code.
Also place the execute query in a System.out.println so that we will know whether a resultset is getting generated or not.
Hi Folks,
Solved this for now .
The thing is i was creating a local variable to generate the List , however was not instantiating it with the value returned from the DAO class.