Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/1941#discussion_r63703169 --- Diff: flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java --- @@ -102,58 +116,62 @@ public void testJDBCOutputFormat() throws IOException, InstantiationException, I .finish(); jdbcOutputFormat.open(0, 1); - jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat() - .setDrivername(DRIVER_CLASS) - .setDBUrl(DB_URL) - .setQuery(SELECT_ALL_BOOKS) - .setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE) - .finish(); - jdbcInputFormat.openInputFormat(); - jdbcInputFormat.open(null); - - Row row = new Row(tuple5.getArity()); - while (!jdbcInputFormat.reachedEnd()) { - if (jdbcInputFormat.nextRecord(row) != null) { + try ( + Connection dbConn = DriverManager.getConnection(JDBCTestBase.DB_URL); + PreparedStatement statement = dbConn.prepareStatement(JDBCTestBase.SELECT_ALL_BOOKS); + ResultSet resultSet = statement.executeQuery(); + ) { + while (resultSet.next()) { + Row row = new Row(tuple5.getArity()); + for (int i = 0; i < tuple5.getArity(); i++) { + row.setField(i, resultSet.getObject(i+1)); + } jdbcOutputFormat.writeRecord(row); } + } catch (SQLException e) { + Assert.fail("JDBC OutputFormat test failed. " + e.getMessage()); } jdbcOutputFormat.close(); - jdbcInputFormat.close(); - jdbcInputFormat.closeInputFormat(); - jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat() - .setDrivername(DRIVER_CLASS) - .setDBUrl(DB_URL) - .setQuery(SELECT_ALL_NEWBOOKS) - .setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE) - .finish(); - jdbcInputFormat.openInputFormat(); - jdbcInputFormat.open(null); - - int recordCount = 0; - while (!jdbcInputFormat.reachedEnd()) { - row = jdbcInputFormat.nextRecord(row); - if (row == null) { - break; - } - if(row.productElement(0)!=null) { Assert.assertEquals("Field 0 should be int", Integer.class, row.productElement(0).getClass());} - if(row.productElement(1)!=null) { Assert.assertEquals("Field 1 should be String", String.class, row.productElement(1).getClass());} - if(row.productElement(2)!=null) { Assert.assertEquals("Field 2 should be String", String.class, row.productElement(2).getClass());} - if(row.productElement(3)!=null) { Assert.assertEquals("Field 3 should be float", Double.class, row.productElement(3).getClass());} - if(row.productElement(4)!=null) { Assert.assertEquals("Field 4 should be int", Integer.class, row.productElement(4).getClass());} - - for (int x = 0; x < 5; x++) { - if(JDBCTestBase.testData[recordCount][x]!=null) { - Assert.assertEquals(JDBCTestBase.testData[recordCount][x], row.productElement(x)); + try ( + Connection dbConn = DriverManager.getConnection(JDBCTestBase.DB_URL); + PreparedStatement statement = dbConn.prepareStatement(JDBCTestBase.SELECT_ALL_NEWBOOKS); + ResultSet resultSet = statement.executeQuery(); + ) { + int recordCount = 0; + while (resultSet.next()) { + Row row = new Row(tuple5.getArity()); + for (int i = 0; i < tuple5.getArity(); i++) { + row.setField(i, resultSet.getObject(i + 1)); + } + if (row.productElement(0) != null) { + Assert.assertEquals("Field 0 should be int", Integer.class, row.productElement(0).getClass()); + } + if (row.productElement(1) != null) { + Assert.assertEquals("Field 1 should be String", String.class, row.productElement(1).getClass()); + } + if (row.productElement(2) != null) { + Assert.assertEquals("Field 2 should be String", String.class, row.productElement(2).getClass()); + } + if (row.productElement(3) != null) { + Assert.assertEquals("Field 3 should be float", Double.class, row.productElement(3).getClass()); + } + if (row.productElement(4) != null) { + Assert.assertEquals("Field 4 should be int", Integer.class, row.productElement(4).getClass()); } - } - recordCount++; - } - Assert.assertEquals(JDBCTestBase.testData.length, recordCount); + for (int x = 0; x < tuple5.getArity(); x++) { + if(JDBCTestBase.testData[recordCount][x]!=null) { --- End diff -- spaces around `!=`
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---