pass string without single quote in spring jdbctemplate


my requirement is to create a insert statement through Spring JDBCTemplate in which I can pass oracle function which execute at database.

e.g - lets assume I have a table employee having column enter_time (datatype is number(20)) and value will be like 20170106213124630560. and insert statement for this table is like -

insert into employee (ID, enter_time ) values (1, to_number(to_char(sys_extract_utc(systimestamp),'YYYYMMDDHH24MISSFF')));

I have to send enter_time from spring JDBCTemplate code like this -


But when I used setString() the value comes with single quote and not able to execute the oracle function. also when I tried with

 preparedStatement.setLong(1, to_number(to_char(sys_extract_utc(systimestamp),'YYYYMMDDHH24MISSFF')));

it give compilation error at 'YYYYMMDDHH24MISSFF'.

Please help me how I can code so that when spring creates a insert statement it can run directly on database.

Please help me to find the solution.

Show source
| java   | oracle   | spring   | database   2017-01-07 15:01 1 Answers

Answers to pass string without single quote in spring jdbctemplate ( 1 )

  1. 2017-01-07 15:01

    You don't need to set it as a parameter as there is nothing that you need to set. systimestamp is oracle built-in. Try this:

    String sql = "insert into TEST_UTC_TIMESTAMP (ID, UTC_TIMESTAMP) values (?, to_number(to_char(sys_extract_utc(systimestamp),'YYYYMMDDHH2‌​4MISSFF')))";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1, 2);
    int n = ps.executeUpdate();

Leave a reply to - pass string without single quote in spring jdbctemplate

◀ Go back