/**
* 获得Oracle连接
* @return
* @throws SQLException
*/
public OracleConnection getOracleConnection() throws SQLException {
Connection conn = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
if(conn instanceof OracleConnection){
return (OracleConnection)conn;
}
//如果 conn不是OracleConnection ,查找是否包含 vendorObj 属性
try {
Field filed = BeanUtils.getDeclaredField(conn, "vendorObj");
Object obj = filed.get(conn);
if(obj instanceof OracleConnection){
return (OracleConnection)obj ;
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw new SQLException("当前连接不能转化为 OracleConnection;"+e.getMessage());
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new SQLException("当前连接不能转化为 OracleConnection;"+e.getMessage());
}catch (NoSuchFieldException e) {
e.printStackTrace();
throw new SQLException("当前连接不能转化为 OracleConnection;"+e.getMessage());
}
throw new SQLException("当前连接不能转化为 OracleConnection;");
}
解决使用weblogic数据源无法获取到 OracleConnection
最新推荐文章于 2024-04-19 17:46:46 发布