diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java index 91e9b5498..d5c7e2f9c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java @@ -84,10 +84,10 @@ private void testTVPResultSet(boolean setSelectMethod, Integer resultSetType, } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.toString()); } finally { - terminateVariation(stmt); + stmt.close(); } } finally { - stmt.close(); + terminateVariation(); } } @@ -133,10 +133,10 @@ private void testTVPStoredProcedureResultSet(boolean setSelectMethod, Integer re ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest); } finally { - terminateVariation(stmt); + stmt.close(); } } finally { - stmt.close(); + terminateVariation(); } } @@ -169,13 +169,13 @@ public void testTVPDataTable() throws SQLException { .prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;")) { pstmt.setStructured(1, tvpName, dt); pstmt.execute(); - } finally { - terminateVariation(stmt); } + } finally { + terminateVariation(); } } - private static void createPreocedure(String procedureName, String destTable, Statement stmt) throws SQLException { + private static void createProcedure(String procedureName, String destTable, Statement stmt) throws SQLException { String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procedureName) + " @InputData " + AbstractSQLGenerator.escapeIdentifier(tvpName) + " READONLY " + " AS " + " BEGIN " + " INSERT INTO " + destTable + " SELECT * FROM @InputData" + " END"; @@ -207,16 +207,18 @@ private void setupVariation(boolean setSelectMethod, Statement stmt) throws SQLE dbStmt.createTable(tableDest); createTVPS(tvpName, tableSrc.getDefinitionOfColumns(), stmt); - createPreocedure(procedureName, tableDest.getEscapedTableName(), stmt); + createProcedure(procedureName, tableDest.getEscapedTableName(), stmt); dbStmt.populateTable(tableSrc); } } - private void terminateVariation(Statement stmt) throws SQLException { - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); - TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); - TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tvpName), stmt); + private void terminateVariation() throws SQLException { + try (Connection conn = DriverManager.getConnection(connectionString); Statement stmt = conn.createStatement()) { + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); + TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); + TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tvpName), stmt); + } } } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlFloat.java b/src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlFloat.java index f1881406f..cdf227dfd 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlFloat.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlFloat.java @@ -27,10 +27,9 @@ public SqlFloat() { public Object createdata() { // for float in SQL Server, any precision <=24 is considered as real so the value must be within // SqlTypeValue.REAL.minValue/maxValue - if (precision > 24) - return Double.longBitsToDouble(ThreadLocalRandom.current().nextLong(((Double) minvalue).longValue(), - ((Double) maxvalue).longValue())); - else { + if (precision > 24) { + return ThreadLocalRandom.current().nextDouble(((Double) minvalue), ((Double) maxvalue)); + } else { return ThreadLocalRandom.current().nextDouble((Float) SqlTypeValue.REAL.minValue, (Float) SqlTypeValue.REAL.maxValue); }