2

有没有办法olap4j.OlapConnection从 a 中得到 a org.h2.jdbc.JdbcConnection

现在我正在尝试这个(如图所示

Class.forName("org.h2.Driver");
Class.forName("mondrian.olap4j.MondrianOlap4jDriver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test;", "sa", "");
OlapWrapper wrapper = (OlapWrapper) conn;
OlapConnection olapConn = wrapper.unwrap(OlapConnection.class);

但我得到一个

线程“主”java.lang.ClassCastException 中的异常:org.h2.jdbc.JdbcConnection 无法在 myprogram.main 中转换为 org.olap4j.OlapWrapper(Mondrian2H2Test.java:67)

:67 是 OlapWrapper wrapper = (OlapWrapper) conn;

编辑 :

我也试过这个:

Class.forName("org.h2.Driver");
Class.forName("mondrian.olap4j.MondrianOlap4jDriver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test;", "sa", "");
OlapConnection olapConn = conn.unwrap(OlapConnection.class);

有了这个结果:

线程“主”java.lang.AbstractMethodError 中的异常:org.h2.jdbc.JdbcConnection.unwrap(Ljava/lang/Class;)Ljava/lang/Object; 在 myprogram.main(Mondrian2H2Test.java:46)

:46 是OlapConnection olapConn = conn.unwrap(OlapConnection.class);

4

1 回答 1

4

查看MondrianOlap4jDriver javadocs邮件列表,代码似乎是:

import java.sql.Connection;
import java.sql.DriverManager;
import org.olap4j.OlapConnection;

Class.forName("mondrian.olap4j.MondrianOlap4jDriver");
Connection conn = DriverManager.getConnection(
    "jdbc:mondrian:" + 
    "Jdbc=jdbc:h2:~/test; " +
    "JdbcUser=sa; " +
    "JdbcPassword=; " +
    "Catalog=file:/mondrian/demo/FoodMart.xml; " +
    "JdbcDrivers=org.h2.Driver");
OlapConnection olapConn = conn.unwrap(OlapConnection.class);
于 2012-05-25T15:38:34.417 回答