Parcourir la source

调整表索引信息获取.

nieqiurong il y a 3 semaines
Parent
commit
7a2097850a

+ 10 - 7
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/jdbc/DatabaseMetaDataWrapper.java

@@ -70,7 +70,7 @@ public class DatabaseMetaDataWrapper {
             try {
                 con.close();
             } catch (SQLException sqlException) {
-                sqlException.printStackTrace();
+                logger.error("关闭数据库连接出现错误:", sqlException);
             }
         });
     }
@@ -82,15 +82,18 @@ public class DatabaseMetaDataWrapper {
     public List<DatabaseMetaDataWrapper.Index> getIndex(String tableName) {
         List<DatabaseMetaDataWrapper.Index> indexList = new ArrayList<>();
         try (ResultSet resultSet = databaseMetaData.getIndexInfo(catalog, schema, tableName, false, false)) {
-            while (resultSet.next()) {
-                Index index = new Index(resultSet);
-                // skip function index
-                if (StringUtils.isNotBlank(index.getColumnName())) {
-                    indexList.add(new Index(resultSet));
+            // clickhouse v2驱动没实现返回了个null
+            if (resultSet != null) {
+                while (resultSet.next()) {
+                    Index index = new Index(resultSet);
+                    // skip function index
+                    if (StringUtils.isNotBlank(index.getColumnName())) {
+                        indexList.add(index);
+                    }
                 }
             }
         } catch (SQLException e) {
-            throw new RuntimeException("读取索引信息:" + tableName + "错误:", e);
+            logger.error("读取{}索引信息出现错误:", tableName, e);
         }
         return indexList;
     }