Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

displaying / using variables in loops  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have successfully managed to extract data from a database and can display it in a loop. The problem though is that I can't put an insert statement in the loop to write the variable to the database. If the query is outside the loop, it won't register. I have tried using request.getParameter , but that brings back 'null'.
This is the code
while (rs.next())
{

String balance = rs.getString(9);
float result = Float.parseFloat(balance);
out.println(balance);

int credit = Integer.parseInt(request.getParameter ("credits"));
out.println(credit);

float newbalance = result - credit;
out.println(newbalance);
}

float test = Float.parseFloat(request.getParameter("newbalance"));
out.println(test); // Brings back null
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and you're saying that when you have these lines inside of the while loop it works??
float test = Float.parseFloat(request.getParameter("newbalance"));
out.println(test); // Brings back null
how can a primitive float like test have a null value?? if the "newbalance" parameter is null, shouldn't you be getting a NullPointeException on the Float.parseFloat() line??
Are you sure you're looking for the right parameter name? what happens when you call request.getParameterNames() do you see the param there?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!