修复PooledConnection可能的数据库驱动未找到问题

This commit is contained in:
Looly 2024-06-18 19:10:40 +08:00
parent 1ce17d8c5c
commit d934831676
2 changed files with 17 additions and 3 deletions

View File

@ -21,6 +21,7 @@
* 【core 】 修复CaseInsensitiveLinkedMap顺序错误问题issue#IA4K4F@Gitee
* 【core 】 修复DateUtil.offset空指针问题issue#3617@Github
* 【core 】 修复PathMover.moveContent问题issue#IA5Q8D@Gitee
* 【db 】 修复PooledConnection可能的数据库驱动未找到问题issue#IA6EUQ@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.28(2024-05-29)

View File

@ -1,6 +1,9 @@
package cn.hutool.db.ds.pooled;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.setting.dialect.Props;
@ -15,7 +18,7 @@ import java.util.Properties;
*
*/
public class PooledConnection extends ConnectionWraper{
private final PooledDataSource ds;
private boolean isClosed;
@ -29,6 +32,16 @@ public class PooledConnection extends ConnectionWraper{
this.ds = ds;
final DbConfig config = ds.getConfig();
// issue#IA6EUQ 部分驱动无法自动加载此处手动完成
final String driver = config.getDriver();
if(StrUtil.isNotBlank(driver)){
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
throw new DbRuntimeException(e);
}
}
final Props info = new Props();
final String user = config.getUser();
if (user != null) {
@ -47,7 +60,7 @@ public class PooledConnection extends ConnectionWraper{
this.raw = DriverManager.getConnection(config.getUrl(), info);
}
public PooledConnection(PooledDataSource ds, Connection conn) {
this.ds = ds;
this.raw = conn;
@ -71,7 +84,7 @@ public class PooledConnection extends ConnectionWraper{
public boolean isClosed() throws SQLException {
return isClosed || raw.isClosed();
}
/**
* 打开连接
* @return this