无法通过 Olap4J 连接到 OLAP Cube API

Cannot connect to OLAP Cube via Olap4J API

我正在尝试使用 Olap4J 连接到 OLAP 多维数据集。我正在使用 jdk14olap4j-1.0.0.445.jar。我知道服务器的 IP 地址和目录。但我无法连接。以下异常似乎是最大的问题:

Server returned HTTP response code: 401 for URL: http://xx.xx.xx.xxx/olap/msmdpump.dll

我是在请求中遗漏了某种身份验证信息还是遗漏了一些更基本的信息?

连接:

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

        OlapConnection con;
        try {
            con = (OlapConnection) DriverManager.getConnection("jdbc:xmla:Server=http://xx.xx.xx.xxx/olap/msmdpump.dll;Catalog=xxx");

            OlapWrapper wrapper = con;
            OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
            OlapStatement stmt = olapConnection.createStatement();
            olapConnection.setCatalog("Analysis Services Tutorial");

            stmt.executeOlapQuery("SELECT {[Customer].[City]} ON Rows FROM [Internet Sales] ");


        } catch (SQLException e) {
            e.printStackTrace();
        }


    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

异常:

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:55443,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Users\name\Documents\project directory\Olap4JTest\target\classes;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\xercesImpl.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\asm.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\asm-commons.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\asm-tree.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\javacup.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\olap4j-1.0.0.445.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\olap4j-jdk14-1.0.0.445.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\olap4j-tck-1.0.0.445.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\olap4j-xmla-1.0.0.445.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\retroweaver.jar;C:\Users\name\Documents\project directory\Olap4JTest\src\lib\retroweaver-rt.jar;C:\Users\name\.m2\repository\backport-util-concurrent\backport-util-concurrent-java12.1\backport-util-concurrent-java12-3.1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.4\lib\idea_rt.jar" main.Main
Connected to the target VM, address: '127.0.0.1:55443', transport: 'socket'
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication5(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/C:/Users/name/Documents/project%20directory/Olap4JTest/target/classes/main/static/scene.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at main.Main.start(Main.java:13)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication12(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait5(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null3(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater4(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null8(WinApplication.java:191)
    ... 1 more
Caused by: java.lang.RuntimeException: org.olap4j.OlapException: This connection encountered an exception while executing a query.
    at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:75)
    at org.olap4j.driver.xmla.DeferredNamedListImpl.size(DeferredNamedListImpl.java:89)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapDatabase(XmlaOlap4jConnection.java:365)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapCatalogs(XmlaOlap4jConnection.java:441)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.setCatalog(XmlaOlap4jConnection.java:397)
    at main.MainController.initialize(MainController.java:30)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 17 more
Caused by: org.olap4j.OlapException: This connection encountered an exception while executing a query.
    at org.olap4j.driver.xmla.XmlaHelper.createException(XmlaHelper.java:35)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:735)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.populateList(XmlaOlap4jConnection.java:708)
    at org.olap4j.driver.xmla.DeferredNamedListImpl.populateList(DeferredNamedListImpl.java:101)
    at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:69)
    ... 23 more
Caused by: org.olap4j.driver.xmla.proxy.XmlaOlap4jProxyException: This proxy encountered an exception while processing the query.
    at org.olap4j.driver.xmla.proxy.XmlaOlap4jHttpProxy.getResponse(XmlaOlap4jHttpProxy.java:158)
    at org.olap4j.driver.xmla.proxy.XmlaOlap4jAbstractHttpProxy.get(XmlaOlap4jAbstractHttpProxy.java:176)
    at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:733)
    ... 26 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://10.96.10.243/olap/msmdpump.dll
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at org.olap4j.driver.xmla.proxy.XmlaOlap4jHttpProxy.getResponse(XmlaOlap4jHttpProxy.java:121)
    ... 28 more
Disconnected from the target VM, address: '127.0.0.1:55443', transport: 'socket'
Exception running application main.Main

Process finished with exit code 1

我遇到了和你一样的问题。我想连接到我的 OLAP 多维数据集,它托管在本地主机上。

我注意到当我在浏览器中向 http://192.168.0.151/OLAP/msmdpump.dll 发送 GET 请求时,我需要输入用户名和密码。我认为我的驱动程序可能无法访问此资源。啊哈!我是对的 ;)

所以我想最简单的解决方案如下:尝试设置匿名IIS身份验证。我知道这不是最好的选择,但是当您只想开始使用 OLAP 时它会起作用。

我的工作连接字符串:

 Connection connection = DriverManager.getConnection(
"jdbc:xmla: Server=http://192.168.0.151/OLAP/msmdpump.dll;" +
"Data Source=http://192.168.0.151/OLAP/msmdpump.dll;" +
"Initial Catalog=AdventureWorksDW2014; " +
"Integrated Security=Basic; " +
"User ID=XXX; " +
"Password=XXX;");

用户 ID - 这是一个数据库用户名 密码 - 这是数据库用户名的密码

更多提示 - 我怀疑您的 olap 查询不是正确的 mdx 查询,因此您可能会得到 OlapException。

祝你好运!