4

We are trying to insert record in hana db so we are currently using jdbc template and key holder to save data and retrieve newly generated column id.This works fine for postgress but not for hana.

query ="SELECT CURRENT_IDENTITY_VALUE() FROM \"HALOSYS\".\"HaloTestDemo\"";  
resultSet =  stmt.executeQuery(query);

Above statement gives current identity value but this doesn't fit into our context where we want to use jdbc template. Please give me idea to fix this. if we add preparedstatement generated keys i am getting follwing exception

com.sap.db.jdbc.exceptions.jdbc40.SQLFeatureNotSupportedException: Method prepareStatement( String, int )() of Connection is not supported.
pruthvi pv
  • 51
  • 3

2 Answers2

0

Try from DUMMY instead of the table name, and do it in the same session as the insert. If you use connection pooling, that will be much harder.

Remi sap
  • 144
  • 6
0

Please prepare your query statement to include insert record and select CURRENT_IDENTITY_VALUE() from the same table into one query statement in an anonymous block as below :

DO BEGIN
    INSERT INTO <TABLE_NAME> .....;
    SELECT CURRENT_IDENTITY_VALUE() FROM <TABLE_NAME>;
END;
Suchitra
  • 101
  • 1
  • 3