Mondrian is a standalone engine that is typically used in a way that is embedded in the application, simply by adding a class library to the classpath. There are actually multiple sets of BI solutions that are integrated Mondrian to achieve multidimensional analysis.
This article describes how to programmatically connect Mondrian and execute MDX queries. Using Mondrian requires a connection to the database and a description file for the multidimensional data (Schema file). This can be learned through my previous article.
http://blog.csdn.net/qzp1991/article/details/44016959
http://blog.csdn.net/qzp1991/article/details/44017161
First, Prerequisites:
1.JDK environment configuration is completed;
2. Complete the deployment of Mondrian servers and multidimensional databases under Tomcat;
Instance of the building, which in my previous article had involved
http://blog.csdn.net/qzp1991/article/details/44016959
Second, the establishment of Java engineering
1. Import the Mondrian Essentials package
They're in mondrian\web-inf\lib.
2. Import the driver connected to MySQL
3. Writing the relevant core code
Package Mondrian.java.api;import Java.io.printwriter;import Mondrian.olap.connection;import Mondrian.olap.drivermanager;import Mondrian.olap.query;import Mondrian.olap.result;public class Main { @ Suppresswarnings ("deprecation") public static void main (string[] args) { Connection Connection = Drivermanager.getconnection ( "Provider=mondrian; jdbc=jdbc:mysql://localhost/nts_eway_ee?user=root&password=root; catalog=e:/apache-tomcat-7.0.40/webapps/mondrian/web-inf/queries/ntsdw.xml; ", null); Query Query =connection.parsequery ("SELECT {[measures].[ Nts_sample]} on COLUMNS, {[region.default].[ Allregion],[region.default]. [Jiangsu], [Region.default]. [Hunan]} On ROWS from [Ntsdw] where [time.default].[ 2015]. [1]. [1] "); result = Connection.Execute (query); PrintWriter pw = new PrintWriter (system.out); Result.print (PW); Pw.flush ();}}
Related explanations
The Mondrian itself performs an MDX query on the interface that is located in the Mondrian.olap package.
Jdbc=jdbc:mysql://localhost/nts_eway_ee?user=root&password=root
Represents the name of the connection database and the associated user name and password
Catalog=e:/apache-tomcat-7.0.40/webapps/mondrian/web-inf/queries/ntsdw.xml;
Indicates where the schema file is located
Query Query =connection.parsequery ("SELECT {[measures].[ Nts_sample]} on COLUMNS, {[region.default].[ Allregion],[region.default]. [Jiangsu], [Region.default]. [Hunan]} On ROWS from [Ntsdw] where [time.default].[ 2015]. [1]. [1] ");
Represents the specific MDX execution statement
Result is the return value of an MDX execution statement
Where thePw.flush () statement is required, otherwise it will not be output
Click Run to execute the results as follows:
Mondrian integration with Java engineering