gong commented on code in PR #4357: URL: https://github.com/apache/incubator-inlong/pull/4357#discussion_r881639102
########## inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/postgres/PostgresJdbcUtils.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.inlong.manager.service.resource.postgres; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.inlong.manager.common.pojo.sink.postgres.PostgresColumnInfo; +import org.apache.inlong.manager.common.pojo.sink.postgres.PostgresTableInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utils for Postgres JDBC. + */ +public class PostgresJdbcUtils { + + private static final String POSTGRES_DRIVER_CLASS = "org.postgresql.Driver"; + private static final String COLUMN_LABEL = "TABLE_NAME"; + private static final String POSTGRES_JDBC_PREFIX = "jdbc:postgresql"; + + private static final Logger LOG = LoggerFactory.getLogger(PostgresJdbcUtils.class); + + /** + * Get Postgres connection from Postgres url and user + */ + public static Connection getConnection(String url, String user, String password) + throws Exception { + if (StringUtils.isBlank(url) || !url.startsWith(POSTGRES_JDBC_PREFIX)) { + throw new Exception( + "Postgres server URL was invalid, it should start with jdbc:postgresql"); + } + Connection conn; + try { + Class.forName(POSTGRES_DRIVER_CLASS); + conn = DriverManager.getConnection(url, user, password); + } catch (Exception e) { + LOG.error("get postgres connection error, please check postgres jdbc url, username " + + "or password", e); + throw new Exception( + "get postgres connection error, please check jdbc url, username or password. " Review Comment: Content is same. May be declare string variable -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
