From 6d75723f3e3bd43895db2470bc5fabb2314dbe8b Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 06 一月 2025 13:27:46 +0800 Subject: [PATCH] 调度记录时间格式化 --- iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/util/JdbcUtils.java | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-) diff --git a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/util/JdbcUtils.java b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/util/JdbcUtils.java index 75f491d..0275079 100644 --- a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/util/JdbcUtils.java +++ b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/core/util/JdbcUtils.java @@ -1,9 +1,14 @@ package com.iailab.framework.mybatis.core.util; +import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.mybatisplus.annotation.DbType; +import com.iailab.framework.common.util.spring.SpringUtils; +import com.iailab.framework.mybatis.core.enums.DbTypeEnum; +import javax.sql.DataSource; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.SQLException; /** * JDBC 工具类 @@ -35,8 +40,22 @@ * @return DB 类型 */ public static DbType getDbType(String url) { - String name = com.alibaba.druid.util.JdbcUtils.getDbType(url, null); - return DbType.getDbType(name); + return com.baomidou.mybatisplus.extension.toolkit.JdbcUtils.getDbType(url); + } + + /** + * 通过当前数据库连接获得对应的 DB 类型 + * + * @return DB 类型 + */ + public static DbType getDbType() { + DynamicRoutingDataSource dynamicRoutingDataSource = SpringUtils.getBean(DynamicRoutingDataSource.class); + DataSource dataSource = dynamicRoutingDataSource.determineDataSource(); + try (Connection conn = dataSource.getConnection()) { + return DbTypeEnum.find(conn.getMetaData().getDatabaseProductName()); + } catch (SQLException e) { + throw new IllegalArgumentException(e.getMessage()); + } } } -- Gitblit v1.9.3