From 1506f626898bea851d011cbf1cee0fc50c39319c Mon Sep 17 00:00:00 2001 From: Ananya Garg Date: Mon, 9 Dec 2024 20:36:26 +0530 Subject: [PATCH] Added test case testRegisterOutParameterWithDecimalException --- .../jdbc/unit/statement/StatementTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index 0f2d5b96f..2fb8de956 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -41,6 +41,7 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; +import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.SQLServerException; @@ -1259,6 +1260,25 @@ public void testBigDecimalPrecision() throws SQLException { } } + @Test + public void testRegisterOutParameterWithDecimalException() throws SQLException { + try (Connection conn = getConnection()) { + String sql = "{call some_procedure(?)}"; + CallableStatement stmt = conn.prepareCall(sql); + + stmt.registerOutParameter(1, Types.DECIMAL); + SQLServerCallableStatement sqlServerStmt = (SQLServerCallableStatement) stmt; + + try { + sqlServerStmt.registerOutParameter(1, Types.DECIMAL); + fail("Expected SQLServerException to be thrown"); + } catch (SQLServerException e) { + assertTrue(e.getCause() instanceof SQLException); + assertEquals("Error fetching scale", e.getCause().getMessage()); + } + } + } + @AfterEach public void terminate() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) {