From 774ef29148e877ef02392adcafbfba8d24c1031d Mon Sep 17 00:00:00 2001 From: v-xiangs Date: Tue, 21 Mar 2017 14:25:06 -0700 Subject: [PATCH 1/3] if the exception is SQLServerException, do not wrap it again with another sql server exception --- .../microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java index adac154df..4929ca285 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java @@ -628,6 +628,9 @@ private void checkClosed() throws SQLServerException { } } } + catch (SQLServerException e) { + throw e; + } catch (SQLException e) { SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false); } From 86ac01e604576e4843d1e44c6601e08060b5c0f6 Mon Sep 17 00:00:00 2001 From: v-xiangs Date: Tue, 21 Mar 2017 14:35:16 -0700 Subject: [PATCH 2/3] added test --- .../ParameterMetaDataTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 1c6d397fd..5db88b2df 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -21,6 +21,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.util.RandomUtil; @@ -54,4 +55,21 @@ public void testParameterMetaDataWrapper() throws SQLException { } } + /** + * Test SQLServerException is not wrapped with another SQLServerException. + * + * @throws SQLException + */ + @Test + public void testSQLServerExceptionNotWrapped() throws SQLException { + try (Connection con = DriverManager.getConnection(connectionString); + PreparedStatement pstmt = connection.prepareStatement("invalid query :)");) { + + pstmt.getParameterMetaData(); + } + catch (SQLServerException e) { + assertTrue(!e.getMessage().contains("com.microsoft.sqlserver.jdbc.SQLServerException"), + "SQLServerException should not be wrapped by another SQLServerException."); + } + } } From 48459654e45c8516b78efdc69282b4ea2cddc89b Mon Sep 17 00:00:00 2001 From: v-xiangs Date: Wed, 22 Mar 2017 09:05:45 -0700 Subject: [PATCH 3/3] added a comment --- .../com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java index 4929ca285..87fe1bcc6 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java @@ -628,6 +628,7 @@ private void checkClosed() throws SQLServerException { } } } + // Do not need to wrapper SQLServerException again catch (SQLServerException e) { throw e; }