public int insert ( String sql , Object [ ] params , String autoGeneratedColumnName ) throws DataAccessException { //dynamic change catalog name sql = changeCatalog ( sql ) ; ReturnIdPreparedStatementCreator psc = new ReturnIdPreparedStatementCreator ( sql , params , autoGeneratedColumnName ) ; KeyHolder keyHolder = new GeneratedKeyHolder ( ) ; try { jdbcTemplate . update ( psc , keyHolder ) ; } catch ( DataAccessException e ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "[" ) ; for ( Object p : params ) { sb . append ( p + " | " ) ; } sb . append ( "]" ) ; logger . error ( "Error SQL: " + sql + " Params: " + sb . toString ( ) ) ; throw e ; } return keyHolder . getKey ( ) . intValue ( ) ; }
insert a row with auto increament id