olap java_OLAP——JAVA

The Problem

You have a Microsoft SQL Server Analysis Services cube you want to get at using Java.  Accessing SSAS from Microsoft clients is a well documented and well travelled path.  Getting data out of SSAS using Java is a less well documented.  It is possible though, due to SSAS's use of XMLA.

The first thing you will need to do is setup HTTP access.  Once this is done there are a few options.  You could develop a web services client to consume the SSAS web service.  Alternatively there are two JDBC drivers I am aware of olap4jand Jdbc4Olap that expose an API for data access.

In my case I had a SQL Server 2008 cube which I wanted to use.  I was developing a suite of dashboards on the Websphere Application Server 7.0  (WAS).  This meant JDK 1.6.  After a lot of experimentation I settled on olap4j, so that is what is used in the examples below.

These instructions, although specific to my environment, should work with any version of SSAS with JDK 1.5 and above.

Overview

To summarise the above.  Your Java program uses a web services client or a JDBC like driver to comminicate with IIS.  The web services client or driver talks XMLA to IIS.  IIS handles the HTTP requests using msmdpump.dll to pass them to SSAS.

Now we need to write our Java program...

olap4jDiagram.PNG?__SQUARESPACE_CACHEVERSION=1267179700789

Step 1 - Setup the JAR file

Copy the .jar files to your class path and then import it in your Java program.

import org.olap4j.*

Step 2 - Setup the Connection

Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");

OlapConnection con = (OlapConnection)DriverManager.getConnection("jdbc:xmla:Server=http://myserver/olap/msmdpump.dll;Catalog=MyCatalog");

OlapWrapper wrapper = (OlapWrapper) con;

OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);

OlapStatement stmt = olapConnection.createStatement();

Step 3 - Execute your OLAP query

Here you can pass any MDX query to SSAS.

CellSet cellSet = stmt.executeOlapQuery("SELECT {[Measures].[Qty], [Measures].[Cost Base]} ON Columns, {[Product].[Category].[Category]} ON Rows FROM [Invoices]");

Step 4 - Process

The code below is using a couple of for loops to populate a dataset from another api.  The key thing is you can access column and rows from the results of the MDX query as you require.

DataSet ds = new DataSet();

for (Position rowPos : cellSet.getAxes().get(1)) {

ds.addRow();

for (Position colPos : cellSet.getAxes().get(0)) {

test += Integer.toString(rowPos.getOrdinal()) + " : " + Integer.toString(colPos.getOrdinal());

Cell cell = cellSet.getCell(colPos, rowPos);

test += "Value: " + cell.getFormattedValue() + "
";

ds.addValue("column" + Integer.toString(colPos.getOrdinal()), cell.getFormattedValue());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值