-
Notifications
You must be signed in to change notification settings - Fork 465
JDBC - Clause Output and Exception #659
Description
Driver version or jar name
Version 6.4
SQL Server version
Microsoft SQL Server 2016 (SP1-CU6) (KB4037354) - 13.0.4457.0 (X64)
Nov 8 2017 17:32:23
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)
Client operating system
Windows 7
Java/JVM version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Table schema
DROP TABLE IF EXISTS TEST;
CREATE TABLE TEST (
ID INT IDENTITY NOT NULL,
FIELD1 VARCHAR(255) NOT NULL,
FIELD2 VARCHAR(255) NOT NULL
);CREATE OR ALTER PROCEDURE [dbo].proc_insert_masse_TEST @json NVARCHAR(MAX)
AS
BEGIN TRANSACTION
BEGIN TRY
SET NOCOUNT ON;
MERGE INTO TEST AS target
USING (
SELECT *
FROM OPENJSON(@json)
WITH (
FIELD1 VARCHAR(255) 'strict $.FIELD1'
)
) AS src
ON (1 = 0)
WHEN NOT MATCHED THEN
INSERT (FIELD1)
VALUES (src.FIELD1)
OUTPUT inserted.ID;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE();
ROLLBACK TRANSACTION;
RAISERROR('Error occured during the insert : %s' , 16, 1, @ErrorMessage);
END CATCH;Problem description
The JDBC driver return an empty result when an error occured.
Expected behavior and actual behavior
When we use this procedure, we should have an error because the column FIELD2 cannot be null.
Repro code
-- Example 1 : should say that the column FIELD2 cannot be null
EXECUTE [dbo].proc_insert_masse_TEST N'[{"FIELD1" : "TEST"}]';
-- Example 2 : Should say that one field is absent
EXECUTE [dbo].proc_insert_masse_TEST N'[{}]';
Note : When we use this example in MSSQL Management tools we have the excepted result, this is why we think that is an issue.