• Post Reply Bookmark Topic Watch Topic
  • New Topic

displaying / using variables in loops  RSS feed

 
Atul Dusara
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
 
Jessica Sant
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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!