@Override public void saveRecord(RoadEntity roadEntity) { if (roadEntity.getId() > 0) { jdbcTemplate.update( SQL_UPDATE_REC, new Object[] { roadEntity.getKod(), roadEntity.getCode(), roadEntity.getCoderus(), roadEntity.getName(), roadEntity.getDlina(), roadEntity.getKodtype(), roadEntity.getId() }); } else { insertRecord(roadEntity); } }
@Override public void insertRecord(final RoadEntity roadEntity) { // kod=?,code=?,code_rus=?,name=?,dlina=?,kodtype=? KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement pst = con.prepareStatement(SQL_INSERT_REC, new String[] {"id"}); pst.setInt(1, roadEntity.getKod()); pst.setString(2, roadEntity.getCode()); pst.setString(3, roadEntity.getCoderus()); pst.setString(4, roadEntity.getName()); pst.setDouble(5, roadEntity.getDlina()); pst.setInt(6, roadEntity.getKodtype()); return pst; } }, keyHolder); roadEntity.setId(keyHolder.getKey().intValue()); }