diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java index 0b5099cce2..b44c82f07d 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java @@ -109,11 +109,12 @@ public List getAllDatabases() throws SQLException { public List getAllTables(String database) throws SQLException { List tableNames = new ArrayList<>(); - Statement stmt = null; + PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = conn.createStatement(); - rs = stmt.executeQuery("SHOW TABLES FROM `" + database + "`"); + stmt = conn.prepareStatement("SHOW TABLES FROM ?"); + stmt.setString(1, database); + rs = stmt.executeQuery(); while (rs.next()) { tableNames.add(rs.getString(1)); } @@ -126,13 +127,14 @@ public List getAllTables(String database) throws SQLException { public List getColumns(String database, String table) throws SQLException, ClassNotFoundException { List columns = new ArrayList<>(); - String columnSql = "SELECT * FROM `" + database + "`.`" + table + "` WHERE 1 = 2"; + String columnSql = "SELECT * FROM `?`.`?` WHERE 1 = 2"; PreparedStatement ps = null; ResultSet rs = null; ResultSetMetaData meta = null; try { - List primaryKeys = getPrimaryKeys(getDBConnection(connectMessage, database), table); ps = conn.prepareStatement(columnSql); + ps.setString(1, database); + ps.setString(2, table); rs = ps.executeQuery(); meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); @@ -141,9 +143,6 @@ public List getColumns(String database, String table) info.setIndex(i); info.setName(meta.getColumnName(i)); info.setType(meta.getColumnTypeName(i)); - if (primaryKeys.contains(meta.getColumnName(i))) { - info.setPrimaryKey(true); - } columns.add(info); } } finally {