Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

problem in passing while loop variables from database

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 69771
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 69771
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, are you hanging up in the loop? Then you might only get one value at all.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how should i get the variable from class1 in class2?
 
Swastik Dey
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks swastik.It works fine.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic