readthefuckingmanual.net

[SOLVED] org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"

Error added: 2013-06-25T19:12:06Z

0 people waiting for the answer...

1 answers found.

Answer 2144 (0.0% helpful)

		KeyHolder holder = new GeneratedKeyHolder();

		final String sql = "INSERT INTO sometable (something, somethingelse) VALUES (?,?)";
		PreparedStatementCreator psc = new PreparedStatementCreator() {

			@Override
			public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
				PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
				ps.setString(1, something);
				ps.setString(2, somethingElse);
				return ps;
			}
		};
		getJdbcTemplate().update(psc, holder);
		return (Integer) holder.getKeyList().get(0).get("id");
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: