fix(util): 优化SQL工具类错误提示信息

This commit is contained in:
2026-01-13 13:34:12 +08:00
parent 0685e3ba28
commit 3b3bfff2c5
2 changed files with 10 additions and 10 deletions
@@ -54,12 +54,12 @@ public final class KitSqlUtil {
try { try {
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName(); className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
} catch (SQLException e) { } catch (SQLException e) {
throw new BadRequestException("Get class name error: =" + jdbcUrl); throw new BadRequestException("获取驱动类名失败,jdbcUrl=" + jdbcUrl);
} }
if (StringUtils.isEmpty(className)) { if (StringUtils.isEmpty(className)) {
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl); DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
if (null == dataTypeEnum) { if (null == dataTypeEnum) {
throw new BadRequestException("Not supported data type: jdbcUrl=" + jdbcUrl); throw new BadRequestException("不支持的数据库类型,jdbcUrl=" + jdbcUrl);
} }
druidDataSource.setDriverClassName(dataTypeEnum.getDriver()); druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
} else { } else {
@@ -82,12 +82,12 @@ public final class KitSqlUtil {
try { try {
int timeOut = 5; int timeOut = 5;
if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) { if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {
log.info("connection is closed or invalid, retry get connection!"); log.info("连接已关闭或者错误,重试获取连接");
connection = dataSource.getConnection(); connection = dataSource.getConnection();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("create connection error, jdbcUrl: {}", jdbcUrl); log.error("创建连接失败, jdbcUrl={}", jdbcUrl);
throw new BadRequestException("create connection error, jdbcUrl: " + jdbcUrl); throw new BadRequestException("创建连接失败, jdbcUrl=" + jdbcUrl);
} finally { } finally {
KitCloseUtil.close(connection); KitCloseUtil.close(connection);
} }
@@ -54,12 +54,12 @@ public final class KitSqlUtil {
try { try {
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName(); className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
} catch (SQLException e) { } catch (SQLException e) {
throw new BadRequestException("Get class name error: =" + jdbcUrl); throw new BadRequestException("获取驱动类名失败,jdbcUrl=" + jdbcUrl);
} }
if (StringUtils.isEmpty(className)) { if (StringUtils.isEmpty(className)) {
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl); DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
if (null == dataTypeEnum) { if (null == dataTypeEnum) {
throw new BadRequestException("Not supported data type: jdbcUrl=" + jdbcUrl); throw new BadRequestException("不支持的数据库类型,jdbcUrl=" + jdbcUrl);
} }
druidDataSource.setDriverClassName(dataTypeEnum.getDriver()); druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
} else { } else {
@@ -82,12 +82,12 @@ public final class KitSqlUtil {
try { try {
int timeOut = 5; int timeOut = 5;
if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) { if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {
log.info("connection is closed or invalid, retry get connection!"); log.info("连接已关闭或者错误,重试获取连接");
connection = dataSource.getConnection(); connection = dataSource.getConnection();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("create connection error, jdbcUrl: {}", jdbcUrl); log.error("创建连接失败, jdbcUrl={}", jdbcUrl);
throw new BadRequestException("create connection error, jdbcUrl: " + jdbcUrl); throw new BadRequestException("创建连接失败, jdbcUrl=" + jdbcUrl);
} finally { } finally {
KitCloseUtil.close(connection); KitCloseUtil.close(connection);
} }