vernedeng commented on code in PR #6939:
URL: https://github.com/apache/inlong/pull/6939#discussion_r1051741286


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/starrocks/StarRocksJdbcUtils.java:
##########
@@ -0,0 +1,217 @@
+/*
+ * 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.sink.starrocks;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hive.jdbc.HiveDatabaseMetaData;
+import org.apache.inlong.manager.pojo.sink.starrocks.StarRocksColumnInfo;
+import org.apache.inlong.manager.pojo.sink.starrocks.StarRocksTableInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class StarRocksJdbcUtils {
+
+    private static final String STAR_ROCKS_DRIVER_CLASS = 
"com.mysql.cj.jdbc.Driver";
+    private static final String METADATA_TYPE = "TABLE";
+    private static final String COLUMN_LABEL = "TABLE_NAME";
+    private static final String STAR_ROCKS_JDBC_PREFIX = "jdbc:mysql";
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(StarRocksJdbcUtils.class);
+
+    /**
+     * Get starRocks connection from starRocks url and user
+     */
+    public static Connection getConnection(String url, String user, String 
password) throws Exception {
+        if (StringUtils.isBlank(url) || 
!url.startsWith(STAR_ROCKS_JDBC_PREFIX)) {
+            throw new Exception("starRocks server url should start with " + 
STAR_ROCKS_JDBC_PREFIX);
+        }
+        Connection conn;
+        try {
+            Class.forName(STAR_ROCKS_DRIVER_CLASS);
+            conn = DriverManager.getConnection(url, user, password);
+            LOGGER.info("get star rocks connection success, url={}", url);
+            return conn;
+        } catch (Exception e) {
+            String errMsg = "get star rocks connection error, please check 
starRocks jdbc url, username or password";
+            LOGGER.error(errMsg, e);
+            throw new Exception(errMsg + ", error: " + e.getMessage());
+        }
+    }
+
+    /**
+     * Execute sql on the specified starRocks Server
+     *
+     * @param sql need to execute
+     * @param url url of starRocks server
+     * @param user user of starRocks server
+     * @param password password of starRocks server
+     * @throws Exception when executing error
+     */
+    public static void executeSql(String sql, String url, String user, String 
password) throws Exception {
+        try (Connection conn = getConnection(url, user, password);
+                Statement stmt = conn.createStatement()) {

Review Comment:
   Does jdbc implementation of starrocks support **_PreparedStatament_**?
   If it does, please use **_PreparedStatament_** to avoid injection



-- 
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]

Reply via email to