Skip to content

Long values are incorrectly stored on Oracle when using SimpleJdbcInsert, instead of SimpleJdbcTemplate [SPR-6912] #11577

@spring-projects-issues

Description

@spring-projects-issues

Jacques-Henri Berthemet opened SPR-6912 and commented

If connected database is Oracle it is not possible to accurately store long values larger than 9999999999999998 or lesser than -9999999999999998 using SimpleJdbcInsert. Inserting wider values would end in a loss of precision (9999999999999999 will be inserted as 10000000000000000).

Here a table creation script :
create table Test (
CustomerId VARCHAR2(16) not null,
Id NUMERIC(19),
constraint PK_Test primary key (Id)
);

Here is a sample Java code to reproduce the issue :
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUrl("jdbc:oracle:thin:sa/sa@oracleHost:1521:XE");
dataSource.setUsername("sa");
dataSource.setPassword("sa");

    SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
    Map<String, Object> parameters = new HashMap<String, Object>();

    parameters.put("customerid", "1");
    parameters.put("id", -9999999999999999L);

    simpleJdbcInsert.setTableName("Test");
    simpleJdbcInsert.execute(parameters);

Here is the result in DB :
SQL> select * from Test;

CUSTOMERID ID


1 -10000000000000000

Now a sample code that works with the same DriverManagerDataSource :

SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
List<Object[]> data = new ArrayList<Object[]>();
data.add(new Object[]{"3",-9999999999999999L});
simpleJdbcTemplate.batchUpdate("insert into Test (customerid, id) values (?,?)", data);

SQL> select * from test;

CUSTOMERID ID


1 -10000000000000000
3 -9999999999999999

FYI There no such issue with MS-SQL Server 2000.


Affects: 3.0 GA, 3.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions