db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Eduardo Santin" <carlos.san...@endeeper.com>
Subject Numeric Field Precision on JavaDB
Date Tue, 20 Jan 2009 20:22:48 GMT
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(){
  try{
   executeTest();
  } catch (SQLException e){
   e.printStackTrace();
  }
 }

 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));
  pstmt.setFloat(2,fltValue);

  pstmt.executeUpdate();

  pstmt.close();
  conn.close();
 }

 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,
Carlos

Mime
View raw message