Github user DaveBirdsall commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafodion/pull/1207#discussion_r133508794
  
    --- Diff: 
dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/BatchTest.java ---
    @@ -158,38 +182,51 @@ public void testBatchInsertPkDuplicate() throws 
Exception {
                 }
             }
             int expectedRowCount = 8;
    +        PreparedStatement insertStmt = null;
    +        Statement selectStmt = null;
     
    -        // Start to prepare and execute the batch upsert
    -        PreparedStatement insertStmt = _conn.prepareStatement(strInsert);
    -        for(int i=0; i < 10; ++i) {
    -            insertStmt.setInt(1, idArray[i]);
    -            insertStmt.setString(2, nameArray[i]);
    -            insertStmt.addBatch();
    -        }
    -        
             try {
    -            statusArray = insertStmt.executeBatch();
    -        } catch(SQLException sqle) {
    -            assertTrue(sqle.getMessage().toUpperCase().contains("BATCH 
UPDATE FAILED")); 
    -            SQLException e = null;
    -            e = sqle.getNextException();
    -            do {
    -                assertTrue(e.getMessage().contains("ERROR[8102] The 
operation is prevented by a unique constraint"));
    -            } while((e = e.getNextException()) != null);
    +            // Start to prepare and execute the batch upsert
    +            insertStmt = _conn.prepareStatement(strInsert);
    +            for(int i=0; i < 10; ++i) {
    +                insertStmt.setInt(1, idArray[i]);
    +                insertStmt.setString(2, nameArray[i]);
    +                insertStmt.addBatch();
    +            }
    +            
    +            try {
    +                statusArray = insertStmt.executeBatch();
    +            } catch(SQLException sqle) {
    +                assertTrue(sqle.getMessage().toUpperCase().contains("BATCH 
UPDATE FAILED")); 
    +                SQLException e = null;
    +                e = sqle.getNextException();
    +                do {
    +                    assertTrue(e.getMessage().contains("ERROR[8102] The 
operation is prevented by a unique constraint"));
    +                } while((e = e.getNextException()) != null);
    +            }
    +            
    +            //assertArrayEquals(expectedStatusArray, statusArray);
    +
    +            int rowCount = 0;
    +            selectStmt = _conn.createStatement();
    +            ResultSet rs = selectStmt.executeQuery(strSelect);
    +            while(rs.next()) {
    +                System.out.println("ID = " + rs.getString(1) + ", Name = " 
+ rs.getString(2));
    +                assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
    +                assertEquals(expectedNameArray[rs.getRow()-1], 
rs.getString(2));
    +                rowCount++;
    +            }
    +            rs.close();
             }
    -        
    -        //assertArrayEquals(expectedStatusArray, statusArray);
    +        finally {
    +            if (selectStmt != null) {
    +                selectStmt.close();
    +            }
     
    -        int rowCount = 0;
    -        ResultSet rs = _conn.createStatement().executeQuery(strSelect);
    -        while(rs.next()) {
    -            System.out.println("ID = " + rs.getString(1) + ", Name = " + 
rs.getString(2));
    -            assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
    -            assertEquals(expectedNameArray[rs.getRow()-1], 
rs.getString(2));
    -            rowCount++;
    -        }
    -        rs.close();
    -        insertStmt.close();
    +            if (insertStmt != null) {
    --- End diff --
    
    I agree. This is fine.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to