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.
How to do a Merge with JDBCTemplate, SQL Server, and expected output
-
30-06-2022 - |
문제
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
해결책
제휴하지 않습니다 StackOverflow