@@ -12724,7 +12724,6 @@ public void testBugIssue464() throws Exception {
1272412724
1272512725 String tableName = "testBugIssue464";
1272612726
12727- final Statement statement = this.conn.createStatement();
1272812727 createTable(tableName, "(c0 INT)");
1272912728
1273012729 Statement bstmt = conn.createStatement();
@@ -12749,4 +12748,48 @@ public void testBugIssue464() throws Exception {
1274912748 }
1275012749 assertEquals(3, counter);
1275112750 }
12751+
12752+ /**
12753+ * Test fix for Issue #484. Verifies that getGeneratedKeys() will work after executing both batch and individual
12754+ * statements.
12755+ *
12756+ * @throws Exception
12757+ */
12758+ @Test
12759+ public void testBugIssue484() throws Exception {
12760+ Properties props = new Properties();
12761+ props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
12762+ props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
12763+ this.conn = getConnectionWithProps(props);
12764+
12765+ String tableName = "testBugIssue484";
12766+
12767+ createTable(tableName, "(c0 INT AUTO_INCREMENT PRIMARY KEY)");
12768+
12769+ Statement stmt = conn.createStatement();
12770+ stmt.addBatch("INSERT INTO " + tableName + " VALUES(1)");
12771+ stmt.addBatch("INSERT INTO " + tableName + " VALUES(2)");
12772+ stmt.executeBatch();
12773+
12774+ ResultSet rs1 = stmt.getGeneratedKeys();
12775+ int counter = 0;
12776+ while (rs1.next()) {
12777+ counter++;
12778+ }
12779+ rs1.close();
12780+ assertEquals(2, counter);
12781+
12782+ stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (DEFAULT)", Statement.RETURN_GENERATED_KEYS);
12783+
12784+ ResultSet rs2 = stmt.getGeneratedKeys();
12785+ counter = 0;
12786+ int key = 0;
12787+ while (rs2.next()) {
12788+ counter++;
12789+ key = rs2.getInt(1);
12790+ }
12791+ rs2.close();
12792+ assertEquals(1, counter);
12793+ assertEquals(3, key);
12794+ }
1275212795}
0 commit comments