Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/1941#discussion_r63162186 --- Diff: flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormat.java --- @@ -94,31 +94,106 @@ private void establishConnection() throws SQLException, ClassNotFoundException { dbConn = DriverManager.getConnection(dbURL, username, password); } } - + /** * Adds a record to the prepared statement. * <p> * When this method is called, the output format is guaranteed to be opened. + * </p> * - * WARNING: this may fail if the JDBC driver doesn't handle null correctly and no column types specified in the SqlRow + * WARNING: this may fail when no column types specified (because a best effort approach is attempted in order to + * insert a null value but it's not guaranteed that the JDBC driver handles PreparedStatement.setObject(pos, null)) * - * @param tuple The records to add to the output. + * @param row The records to add to the output. + * @see PreparedStatement * @throws IOException Thrown, if the records could not be added due to an I/O problem. */ @Override - public void writeRecord(Row tuple) throws IOException { + public void writeRecord(Row row) throws IOException { + if (typesArray != null && typesArray.length > 0 && typesArray.length == row.productArity()) { + LOG.warn("Column SQL types array doesn't match arity of passed Row! Check the passed array..."); + } try { - for (int index = 0; index < tuple.productArity(); index++) { - if (tuple.productElement(index) == null && typesArray != null && typesArray.length > 0) { - if (typesArray.length == tuple.productArity()) { - upload.setNull(index + 1, typesArray[index]); - } else { - LOG.warn("Column SQL types array doesn't match arity of SqlRow! Check the passed array..."); - } + for (int index = 0; index < row.productArity(); index++) { + if (typesArray == null ) { --- End diff -- I would move this check out of the loop, i.e., ``` if (typesArray == null) { for (...) { //... upload.setObject(...) } } else { for (...) { // ... } } ```
--- 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. ---