use of cn.hutool.db.ds.DataSourceWrapper in project hutool by looly.
the class DriverUtil method identifyDriver.
/**
* 识别JDBC驱动名
*
* @param ds 数据源
* @return 驱动
*/
public static String identifyDriver(DataSource ds) {
if (ds instanceof DataSourceWrapper) {
final String driver = ((DataSourceWrapper) ds).getDriver();
if (StrUtil.isNotBlank(driver)) {
return driver;
}
}
Connection conn = null;
String driver;
try {
try {
conn = ds.getConnection();
} catch (SQLException e) {
throw new DbRuntimeException("Get Connection error !", e);
} catch (NullPointerException e) {
throw new DbRuntimeException("Unexpected NullPointException, maybe [jdbcUrl] or [url] is empty!", e);
}
driver = identifyDriver(conn);
} finally {
DbUtil.close(conn);
}
return driver;
}
Aggregations