package mondrianTest; import java.io.PrintWriter; import mondrian.olap.Connection; import mondrian.olap.DriverManager; import mondrian.olap.Query; import mondrian.olap.Result; public class TestMDX { public void testQuery(){ Connection connection = DriverManager.getConnection("Provider=mondrian;" + "Jdbc=jdbc:mysql://10.241.20.157:3306/foodmart?user=root&password=root;" + "Catalog=C:\\Users\\Administrator\\Desktop\\nrtp\\FoodMart.xml;", null, false); Query query = connection.parseQuery("select {[Measures].[业务量]} on columns from MsgBusi"); Result result = connection.execute(query); PrintWriter pw = new PrintWriter(System.out); result.print(pw); pw.flush(); } public static void main(String[] args) { TestMDX a = new TestMDX(); System.out.println("调用mondrian api进行查询"); a.testQuery(); } }
Exception in thread "main" mondrian.olap.MondrianException: Mondrian Error:Internal error: while parsing catalog C:\Users\Administrator\Desktop\nrtp\FoodMart.xml at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:755) at mondrian.olap.Util.newInternal(Util.java:1083) at mondrian.olap.Util.newError(Util.java:1099) at mondrian.rolap.RolapSchema.load(RolapSchema.java:303) at mondrian.rolap.RolapSchema.<init>(RolapSchema.java:213) at mondrian.rolap.RolapSchema.<init>(RolapSchema.java:76) at mondrian.rolap.RolapSchema$Pool.get(RolapSchema.java:835) at mondrian.rolap.RolapSchema$Pool.get(RolapSchema.java:657) at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:148) at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:79) at mondrian.olap.DriverManager.getConnection(DriverManager.java:122) at mondrian.olap.DriverManager.getConnection(DriverManager.java:87) at mondrian.olap.DriverManager.getConnection(DriverManager.java:55) at mondrianTest.TestMDX.testQuery(TestMDX.java:13) at mondrianTest.TestMDX.main(TestMDX.java:41) Caused by: org.eigenbase.xom.XOMException: In Schema: In Cube: In Measure: In MeasureExpression: In SQL: Value 'infobright' of attribute 'dialect' has illegal value 'infobright'. Legal values: {generic, access, db2, derby, firebird, hsqldb, mssql, mysql, oracle, postgres, sybase, teradata, ingres, luciddb} at mondrian.olap.MondrianDef$Schema.<init>(MondrianDef.java:134) at mondrian.rolap.RolapSchema.load(RolapSchema.java:289) ... 11 more
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:408) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2490) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:408) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at mondrianTest.TestMysql.main(TestMysql.java:17) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.<init>(Unknown Source) at java.net.Socket.<init>(Unknown Source) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305) ... 15 more
Exception in thread "main" mondrian.olap.MondrianException: Mondrian Error:Failed to parse query 'select {[Measures].[业务量]} on columns from MsgBusi' at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:755) at mondrian.olap.ConnectionBase.parseQuery(ConnectionBase.java:77) at mondrian.olap.ConnectionBase.parseQuery(ConnectionBase.java:59) at mondrianTest.TestMDX.testQuery(TestMDX.java:18) at mondrianTest.TestMDX.main(TestMDX.java:37) Caused by: mondrian.olap.MondrianException: Mondrian Error:Error while parsing MDX statement 'select {[Measures].[业务量]} on columns from MsgBusi' at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:755) at mondrian.olap.Parser.parseInternal(Parser.java:760) at mondrian.olap.ConnectionBase.parseQuery(ConnectionBase.java:74) ... 3 more Caused by: mondrian.olap.MondrianException: Mondrian Error:MDX cube 'MsgBusi' not found or not processed at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:752) at mondrian.rolap.RolapSchema.lookupCube(RolapSchema.java:1067) at mondrian.olap.Query.<init>(Query.java:187) at mondrian.olap.Parser.makeQuery(Parser.java:851) at mondrian.olap.CUP$Parser$actions.CUP$Parser$do_action(Parser.java:1700) at mondrian.olap.Parser.do_action(Parser.java:685) at java_cup.runtime.lr_parser.parse(lr_parser.java:569) at mondrian.olap.Parser.parseInternal(Parser.java:755) ... 4 more
Axis #0: {[Customers].[USA].[CA]} Axis #1: {[Measures].[Unit Sales]} Axis #2: {[Time].[1997]} Row #0: 74,748
Exception in thread "main" java.lang.NoSuchMethodError: mondrian.resource.MondrianResource.getThreadOrDefaultLocale()Ljava/util/Locale; at mondrian.resource.MondrianResource.instance(MondrianResource.java:29) at mondrian.rolap.aggmatcher.AggTableManager.<clinit>(AggTableManager.java:54) at mondrian.rolap.RolapSchema.<init>(RolapSchema.java:194) at mondrian.rolap.RolapSchema.<init>(RolapSchema.java:216) at mondrian.rolap.RolapSchemaPool.get(RolapSchemaPool.java:214) at mondrian.rolap.RolapSchemaPool.get(RolapSchemaPool.java:66) at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:160) at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:90) at mondrian.olap.DriverManager.getConnection(DriverManager.java:112) at mondrian.olap.DriverManager.getConnection(DriverManager.java:68) at mondrian.olap.DriverManager.getConnection(DriverManager.java:50) at mondrianTest.TestMDX.testQuery(TestMDX.java:13) at mondrianTest.TestMDX.main(TestMDX.java:38)
<dependency> <groupId>eigenbase</groupId> <artifactId>eigenbase-resgen</artifactId> <version>1.3.1</version> </dependency>
<dependency> <groupId>eigenbase</groupId> <artifactId>eigenbase-resgen</artifactId> <version>1.3.0.11873</version> </dependency>
package mondrianTest; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import org.olap4j.Cell; import org.olap4j.CellSet; import org.olap4j.OlapConnection; import org.olap4j.OlapException; import org.olap4j.OlapStatement; import org.olap4j.OlapWrapper; import org.olap4j.Position; import org.olap4j.metadata.Member; public class Olap4jTest { /** * 获取连接Olap的连接 * @param url 连接Olap的URL * @return * @throws ClassNotFoundException * @throws SQLException */ public static OlapConnection getConnection(String url) throws ClassNotFoundException, SQLException{ Class.forName("mondrian.olap4j.MondrianOlap4jDriver"); Connection connection = DriverManager.getConnection(url); OlapConnection olapConnection = connection.unwrap(OlapConnection.class); return olapConnection; } /** * 获取查询的结构结果集 * @param mdx mdx查询语句 * @param conn Olap连接 * @return * @throws OlapException */ public static CellSet getResultSet(String mdx,OlapConnection conn) throws OlapException{ OlapStatement statement = conn.createStatement(); CellSet cellSet = statement.executeOlapQuery(mdx); return cellSet; } public void testQuery(){ OlapConnection connection = null; try { connection = getConnection("jdbc:mondrian:" + "Jdbc=jdbc:mysql://10.241.20.157:3306/foodmart?user=root&password=root;" + "Catalog=C:\\Users\\Administrator\\Desktop\\nrtp\\FoodMart.xml;"); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String query = "SELECT { [Measures].[Unit Sales] } on columns,{ [Time].[Year].[1997] } on rows FROM Sales WHERE ([Customers].[State Province].[CA])"; //获取查询结果 CellSet cs = null; try { cs = getResultSet(query, connection); } catch (OlapException e) { // TODO Auto-generated catch block e.printStackTrace(); } PrintWriter pw = new PrintWriter(System.out); //处理返回数据 if(cs.getAxes().size()>1){ for (Position row : cs.getAxes().get(1)) { for (Position column : cs.getAxes().get(0)) { for (Member member : row.getMembers()) { System.out.println("rows:"+member.getUniqueName()); } for (Member member : column.getMembers()) { System.out.println("columns:"+member.getUniqueName()); } final Cell cell = cs.getCell(column, row); System.out.println("values:"+cell.getValue()); System.out.println(); } } }else{ for(Position column:cs.getAxes().get(0)) { for(Member member:column.getMembers()){ System.out.println("columns:"+member.getUniqueName()); } Cell cell=cs.getCell(column); System.out.print("values:"+cell.getValue()); System.out.println(); } } } public static void main(String[] args) { Olap4jTest a = new Olap4jTest(); System.out.println("调用mondrian api进行查询"); a.testQuery(); } }
rows:[Time].[1997] columns:[Measures].[Unit Sales] values:74748.0
原文地址:http://blog.csdn.net/yu616568/article/details/44063877