You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John Sidney-Woollett <jo...@wardbrook.com> on 2003/11/26 08:43:53 UTC
Re: Invalid Number error when regional setting set to English
(Canada )
If you're saving numeric data back to an Oracle (or any) database, then
consider using binding native java data types instead of passing strings
in your update/insert statements or calls to stored procs.
For example, instead of:
String qry = "update CUSTOMER set TOTAL_INVOICED = " + numValStr +
"where CUSTOMER_ID = " + custIDStr;
Statement stmnt = conn.createStatement();
stmnt.executeUpdate(qry);
Try using the following:
Double invoiced = Double.parseDouble(numValStr);
int custID = Integer.parseInt(custIDStr);
String qry = "update CUSTOMER set TOTAL_INVOICED = ? where CUSTOMER_ID ?";
PreparedStatement ps = conn.prepareStatement(qry);
ps.setDouble(1, invoiced);
ps.setInt(2, custID);
ps.executeUpdate();
You will be able to perform better checking because you are being forced
to convert the data from strings prior to inserting/updating the records,
and handle any errors, and you will see a performance gain using the
preparedstatement because Oracle will compile the statement once, and
re-use it without re-compiling it when it is used again (even when the
parameters have different values).
Hope that helps.
John
Lisa Wong said:
> I have a Java/struts app running on a Windows box. If the box has the
> regional setting set to English (Canada), I am unable to save decimal
> numbers as somewhere along the way, it changes the decimal to a comma.
>
> I've run the package by itself on the box and it works fine, but through
> the
> app I get an ORA-017222 Invalid Number. If I do a select via the app, I
> can
> actually see the decimal replaced by a comma on the screen. It's fine if
> set to English (US) and most of the other English settings.
>
> Has anyone experienced something like this?
>
> Any suggestions would be helpful.
>
> thx,
>
> Lisa Wong
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org