从org.h2.jdbc.JdbcConnection获取olap4j.OlapConnection

有没有办法从 org.h2.jdbc.JdbcConnection 获取 olap4j.OlapConnection

现在我正在尝试(如 ):

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);

但我得到了一个

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

:67是 OlapWrapper wrapper =(OlapWrapper)conn;

EDIT :

我也试过这个:

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

有了这个结果:

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

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

0
额外 编辑
意见: 1

1 答案

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

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);
0
额外
谢谢!我已经删除了有关密码的评论。
额外 作者 Thomas Mueller,
这对我来说很合适。蒙德里安绝对可以传递空密码。
额外 作者 Julian Hyde,