Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error w/form submission/getting price values

Status
Not open for further replies.

sknyppy

Programmer
May 14, 1999
137
US
I have a form field where user enters the price of something and I need to access that form value and save it to my MSSQL table into a FLOAT field. I keep receiving errors like:

---------------------------------------
java.lang.NullPointerException
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
---------------------------------------


<!---form page--->
<input type=&quot;text&quot; size=&quot;8&quot; name=&quot;price&quot;>

<!---process page--->
try {
price = Double.parseDouble(request.getParameter(&quot;price&quot;));
}
catch (NumberFormatException nx) { price= 0.0D; }

Any help please....

Thanks




 
Are you sure your call from
Code:
 request.getParameter(&quot;price&quot;)
is returning a decent value ? I would imagine it is not.

Try debugging ... print out the value of &quot;price&quot; before you try to parse it ...
 
Yep I finally figured that part out by doing the following

double Price = 0.00;
try {
String Price_temp = request.getParameter(&quot;Price&quot;);
if (Price_temp == null || Price_temp.equals(&quot;&quot;))
Price_temp = &quot;0.00&quot;;
Price= Double.parseDouble(Price_temp);
}
catch (NumberFormatException nx) { }



But now I keep receiving the following error msg:
---------------
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
---------------

Any ideas?
 
Hi,

I agree with sedj, its always good to print the request parameter before type casting.

Try this,

price = Double.parseDouble
(request.getParameter(&quot;price&quot;).trim());

Cheers,
venu
 
>>>> Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
Indicates you are trying to pass a dodgy value in your db call. Check your values by printing them out before you call the database - you'll see an anomaly I imagine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top