Pregunta

My query looks like this

MERGE dbo.myTable AS myt
USING (SELECT ? AS ID,
       ? AS Value) AS s
ON (s.id = myt.id)
WHEN MATCHED THEN
    UPDATE SET myt.ApprovalUserId = s.ApprovalUserId
WHEN NOT MATCHED THEN
    INSERT ( Value )
    VALUES  ( s.Value)
OUTPUT INSERTED.id;

My java code looks like this

jdbcTemplate.queryForInt(SQL, id, value);

But when I try to run I get

java.sql.SQLException: The executeQuery method must return a result set.

I would like to somehow extract the ID given by the merge "INSERTED.id". Is there a JDBCTemplate method that I should be looking at? Or should I abandon merge and just do this with selects, updates, and locks?

I'm using Sql Server 2012, Java 6, and Spring jdbc 3.1.2.release

¿Fue útil?

Solución

The final solution for me was to extend the JdbcTemplate class "StoredProcedure" and to throw my merge statement into a stored procedure. The execute command returned all of the stored procedure results.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top