This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying / using variables in loops

 
Atul Dusara
Greenhorn
Posts: 3
  • 0
  • 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
  • 0
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic