• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!