wuchong commented on a change in pull request #8867: [FLINK-12956][jdbc] Introduce upsert table sink for JDBC URL: https://github.com/apache/flink/pull/8867#discussion_r298556877
########## File path: flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/AbstractJDBCOutputFormat.java ########## @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.api.java.io.jdbc; + +import org.apache.flink.api.common.io.RichOutputFormat; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.types.Row; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +/** + * OutputFormat to write Rows into a JDBC database. + * + * @see Row + * @see DriverManager + */ +public abstract class AbstractJDBCOutputFormat<T> extends RichOutputFormat<T> { + + private static final long serialVersionUID = 1L; + static final int DEFAULT_BATCH_INTERVAL = 5000; + + private static final Logger LOG = LoggerFactory.getLogger(AbstractJDBCOutputFormat.class); + + private final String username; + private final String password; + private final String drivername; + private final String dbURL; + + protected Connection dbConn; + + public AbstractJDBCOutputFormat(String username, String password, String drivername, String dbURL) { + this.username = username; + this.password = password; + this.drivername = drivername; + this.dbURL = dbURL; + } + + @Override + public void configure(Configuration parameters) { + } + + protected void establishConnection() throws SQLException, ClassNotFoundException { + Class.forName(drivername); Review comment: Is the `drivername` necessary here? For example, if users use `jdbc:mysql:mydb:mytable` as the url, does he still need to specify the MySQL driver full qualified name `com.mysql.jdbc.Driver`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
