This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes problem in passing while loop variables from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in passing while loop variables from database" Watch "problem in passing while loop variables from database" New topic
Author

problem in passing while loop variables from database

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

I am getting records from the database and store it in a string variable inside while loop.When i tried to access the variable in another class,i am getting the top most record saved inside the while loop
my code follows:
class1:



class 2:



Actually the records in the database contains aircel and airtel.But when i run this code, i am getting only aircel.

How can i get all the records taken from the database.please assist me to do this.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Are you always updating the same String? In which case you lose the previous value every time you traverse the loop. Try adding the Strings to a List<String> and return that List.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Or, are you hanging up in the loop? Then you might only get one value at all.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
When i run the class1 alone without calling class2,i can able to get all the records from the database.But if i call class2 from class1 and tried to access the variable campaign1 from class1,it just prints the top most record.

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2504
    
    8

In class2.service() (created in class1.service) you are again creating a new class1, and trying to read a static member from that. Why?

What does the hangup() do in your class2 ? Maybe it causes the end of the loop in the original class1?


OCUP UML fundamental and ITIL foundation
youtube channel
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Atually,I need to pass the variable "campaign1" from class1 to class 2.Thats why in class2,i am calling class1's variable.

This is an ivr application.hangup is to cut the customer's call after the ivr gets completed.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2504
    
    8

Let's find the problem step by step:
Replace, in class1

By


Show us the output.

Then, replace by


Show us the output again.

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
sorry for the delayed reply due to unavoidable circumstances.

output for the code:


is

aircel
airtel


output for the code:


is

aircel
.

where am i wrong here.please assist me.

Thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6



Swastik
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Then how should i get the variable from class1 in class2?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks swastik.It works fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in passing while loop variables from database