Color me silly, but what do you think will happen when you try to store a floating point number in to a numeric/decimal numeric string?


The numeric string isn’t a floating point number. It looks like your floating point number is being round down when it’s automatically converted to a decimal string.


When you insert it as ’11.11’ it is a numeric string so it gets inserted correctly.


Does that make sense?



From: Carlos Eduardo Santin []
Sent: Tuesday, January 20, 2009 2:23 PM
Subject: Numeric Field Precision on JavaDB


Hi everybody,


Have someone had a problem like this one before?


If I have a simple table like:


create table test(id integer, percent numeric(5,2))


And I use a java code to insert data into this table:



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;


public class TestJavaDB{


 public TestJavaDB(){
  } catch (SQLException e){


 public void executeTest() throws SQLException{
  Connection conn = DriverManager.getConnection("jdbc:derby:C:/Derby20090108/data/", "root", "root");
  Float fltValue = 11.11F;


  String strQuery = "INSERT INTO test VALUES (?, ?)";


  PreparedStatement pstmt = conn.prepareStatement(strQuery);
  pstmt.setInt(1,new Integer(2));






 public static void main(String[] args){
  new TestJavaDB();



The value inserted into the field percent in the database is 11.10 and not 11.11 as it would be.


But if I insert this data directly in the database using a script:


INSERT INTO test VALUES (1, 11.11);


The value appears correctly.


Is there any bug related to the derby jdbc library??



Thanks in advance,