title: Spring JDBC - Last inserted id
body: <p>I'm using Spring JDBC. Is a simple way to get last inserted ID using Spring Framework or i need to use some JDBC tricks ?</p>
  
  <pre><code>jdbcTemplate.update("insert into test (name) values(?)", params, types);
  // last inserted id ...
  </code></pre>
  
  <p>I found something like below, but i get: <code>org.postgresql.util.PSQLException: Returning autogenerated keys is not supported.</code></p>
  
  <pre><code>KeyHolder keyHolder = new GeneratedKeyHolder();
  jdbcTemplate.update(new PreparedStatementCreator() {
  
      @Override
      public PreparedStatement createPreparedStatement(
              Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement("insert into test (name) values(?)", new String[] {"id"});
          ps.setString(1, "test");
          return ps;
      }
  
  }, keyHolder);
  lastId = (Long) keyHolder.getKey();
  </code></pre>