Skip to content

Commit 978d8f3

Browse files
committed
Added a new test for execute API with set no count
1 parent 596aafc commit 978d8f3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,30 @@ public void testPrepStmtNoCountExecuteUpdateInsertAndGenKeys() {
27952795
}
27962796
}
27972797

2798+
/**
2799+
* Tests executeUpdate using PreparedStatement for Insert followed by getGenerateKeys
2800+
*
2801+
* @throws Exception
2802+
*/
2803+
@Test
2804+
public void testPrepStmtNoCountExecuteInsertAndGenKeys() {
2805+
try (Connection con = getConnection()) {
2806+
String sql = "SET NOCOUNT ON; INSERT INTO " + tableName + " (NAME) VALUES('test')";
2807+
try(PreparedStatement stmt = con.prepareStatement(sql,PreparedStatement.RETURN_GENERATED_KEYS)) {
2808+
stmt.execute();
2809+
try (ResultSet generatedKeys = stmt.getGeneratedKeys()) {
2810+
if (generatedKeys.next()) {
2811+
int id = generatedKeys.getInt(1);
2812+
assertEquals(id, 4, "id should have been 4, but received : " + id);
2813+
}
2814+
}
2815+
}
2816+
} catch (SQLException e) {
2817+
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
2818+
}
2819+
}
2820+
2821+
27982822
/**
27992823
* Tests execute for Insert followed by getGenerateKeys
28002824
*

0 commit comments

Comments
 (0)