2014-04-30 45 views
1

我有一个数据源,它有一个提供程序MSOLAP我想通过基于Java的应用程序连接到此源。我用下面的:使用Java连接MS OLAP

public static void main(String[] args) throws Exception { 

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

    // Connect 
    final Connection connection = 
      DriverManager.getConnection(
       // This is the SQL Server service end point. 
       "jdbc:xmla:Server=http://localhost:81/mondrian/xmla" 

       // Tells the XMLA driver to use a SOAP request cache layer. 
       // We will use an in-memory static cache. 
       + ";Cache=org.olap4j.driver.xmla.cache.XmlaOlap4jNamedMemoryCache" 

       // Sets the cache name to use. This allows cross-connection 
       // cache sharing. Don't give the driver a cache name and it 
       // disables sharing. 
       + ";Cache.Name=MyNiftyConnection" 

          // Some cache performance tweaks. 
          // Look at the javadoc for details. 
          + ";Cache.Mode=LFU;Cache.Timeout=600;Cache.Size=100", 

        // XMLA is over HTTP, so BASIC authentication is used. 
        null, 
        null); 

    // We are dealing with an olap connection. we must unwrap it. 
    final OlapConnection olapConnection = connection.unwrap(OlapConnection.class); 

    // Check if it's all groovy 
    ResultSet databases = olapConnection.getMetaData().getDatabases(); 
    databases.first(); 
    System.out.println(
      olapConnection.getMetaData().getDriverName() 
        + " -> " 
        + databases.getString(1)); 

    // Done 
    connection.close(); 
} 

我得到的类OlapConnection未编译。我有两个问题:1-我使用maven来构建这个测试,但它没有显示错误,为什么不能找到这个类?

2-是否有任何其他方式连接到MSOLAP而不使用olap4j?

回答

1

这不是远程连接到XMLA服务的方式。首先阅读this code,然后您需要编辑连接字符串。

在SSAS,连接字符串应该是这个样子:

jdbc:xmla:Server=http://localhost/olap/msmdpump.dll;Catalog=myCatalog 
+0

我已经试过您指定的例子,但仍maven的依赖性无法提供OlapConnection类。我更新了代码 –

+0

如果您的问题与Maven有关,那么这是一个单独的问题,根本与olap4j无关。我建议确保你包含org.olap4j:olap4j和org.olap4j:olap4j-xmla作为依赖关系。 – Luc