• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Java Sybase -->Arithmetic overflow

 
Ranch Hand
Posts: 63
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fellow ranchers,
my application tries to insert data into sybase database.I use the JDBC preparedstatement.It is a simple insert query.
One of the fields is field1 which is defined as Numeric(38,14) in database.But i get the error when i call the preparedstatement.executeUpdate();
-----------------------------------------------------------------

-----------------------------------------------------------------
The value passed to the preparedstatement is
preparedStatement.setDouble( 0,myBean.getField().doubleValue());
and it is 6778.68 !!!

also i use a convert function in the stored procedure when performing the insertion in the database
convert(numeric(38,14),@field1)
------------------------------------------------
can someone please suggest how to handle this situation
thanks in advance
cheers
vinny m
[ June 17, 2008: Message edited by: Vinny Menon ]
 
Marshal
Posts: 79656
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should know that in SQL a "float" is maintained in floating-point arithmetic (as in Java, but in SQL I think it is 64 bits), and that floating-point arithmetic is imprecise. Go through the search facility on JavaRanch, and also this FAQ (no 20) and you will find lots of examples.

In SQL a "numeric" is stored as a String; obviously when the values are converted there is rounding "up."
 
Vinny Menon
Ranch Hand
Posts: 63
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much.my issue is resolved.
 
expectation is the root of all heartache - shakespeare. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic