f-angi
5/23/2016 - 3:15 PM

Retrieves the id of the inserted row

Retrieves the id of the inserted row

public long insert() {
    KeyHolder keyHolder = new GeneratedKeyHolder();

    try {
        jdbcTemplate.update(new PreparedStatementCreator() {

            public PreparedStatement createPreparedStatement(Connection connection)
                throws SQLException {

                PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[] {
                    "ID_BOZZA_DENUNCIA"
                });
                ps.setLong(1, draft.getIdDenuncia());
                ps.setBytes(2, draft.getSerializedDraft());
                return ps;
            }
        }, keyHolder);

        return (Long) keyHolder.getKey().longValue();
}