目录:
1.获取org.olap4j.OlapConnection对象
2.获取mondrian.olap.Connection对象
一、org.olap4j.OlapConnection对象
说明:先获取jdbc连接(java.sql.Connection);再转换成org.olap4j.OlapConnection。
package gov.bi.util; import java.sql.Connection; import java.sql.DriverManager; import org.olap4j.OlapConnection; public class TEST { public static void main(String[] args)throws Exception { Class.forName("mondrian.olap4j.MondrianOlap4jDriver"); Connection conn = DriverManager.getConnection( "jdbc:mondrian:" + "Jdbc=jdbc:oracle:thin:@10.11.8.173:1521:orcl; " + "JdbcUser=develop; " + "JdbcPassword=123; " + "Catalog=file:E:\cube_xml\91dd93f.xml; " + "JdbcDrivers=oracle.jdbc.driver.OracleDriver"); OlapConnection olapConn = conn.unwrap(OlapConnection.class); System.out.println(olapConn); } }
二、获取mondrian.olap.Connection对象
package gov.bi.util; import mondrian.olap.Connection; import mondrian.olap.DriverManager; import mondrian.olap.Util.PropertyList; import mondrian.spi.CatalogLocator; import mondrian.spi.impl.CatalogLocatorImpl; public class T { public static void main(String[] args) throws Exception{ // 加载MondrianOlap4jDriver驱动 Class.forName("mondrian.olap4j.MondrianOlap4jDriver"); PropertyList propList = new PropertyList(); propList.put("Provider", "mondrian");// 必须是mondrian propList.put("Catalog", "e:\abc.xml");// cube文件路径 //jdbc相关信息 propList.put("JdbcDrivers", "oracle.jdbc.driver.OracleDriver"); propList.put("Jdbc", "jdbc:oracle:thin:@10.11.8.173:1521:orcl"); propList.put("JdbcUser","develop"); propList.put("JdbcPassword","admin"); // cube文件 CatalogLocator locator = new CatalogLocatorImpl(); locator.locate("e:\abc.xml"); Connection connection = DriverManager.getConnection(propList, locator); } }