OLAP JDBC连接

时间:2019-03-15 07:37:55

标签: java jdbc jar ssas olap-cube

我正在尝试使用JDBC连接到我在SSMS中创建的多维数据集(我的数据库名称是AdventureWorks)。

  • 我应该在哪里放置连接URL,
  • 我的连接URL是否正确?

我已经为olap4j添加了jar文件,但是在执行时我得到了classNotFoundException。这是我使用的代码:

package oLapConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.olap4j.OlapConnection;

public class Olap {
    public static void main(String [] args) throws SQLException {
        // Load the driver
        try {
            Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Connect
        final Connection connection =
                DriverManager.getConnection(
                    // This is the SQL Server service end point.
                    "jdbc:xmla:Server=http://localhost/olap/msmdpump.dll;Catalog=myCatalog"

                    // 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();
    }
}

感谢您的帮助。您可以告诉我任何有帮助的相关文章或链接。如果问题不清楚,请指导我。

0 个答案:

没有答案