1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| import mondrian.olap.Axis;
import mondrian.olap.Connection;
import mondrian.olap.DriverManager;
import mondrian.olap.Member;
import mondrian.olap.Position;
import mondrian.olap.Query;
import mondrian.olap.Result;
public class MondrianMoteur
{
public static void main(String[] args)
{
String configuration =
"Provider=mondrian;" +
"jdbc:mysql://localhost/Foodmart?user=root&password=123;" +
"Catalog=C:\\Tomcat 6.0\\webapps\\mondrian\\WEB-INF\\queries\\FoodMart.xml;" +
"JdbcDrivers=com.mysql.jdbc.Driver;";
String mdx =
" select {[Measures].[Store Cost]," +
" [Measures].[Store Sales]} ON COLUMNS," +
" {[Product].[All Products]} ON ROWS" +
" from [Sales]";
new MondrianMoteur().executeRequete(configuration, mdx);
}
// @SuppressWarnings({ "deprecation", "null" })
private void executeRequete(String configuration, String requete)
{
Connection connection = null;
try
{
DriverManager.getConnection(configuration, null, true);
Query query = connection.parseQuery(requete);
Result result = connection.execute(query);
afficherResultat(result);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (connection != null)
connection.close();
}
}
private void afficherResultat(Result result)
{
Axis[] axis = result.getAxes();
for (int i = 0; i < axis.length; i++)
for (Position p : axis[i].getPositions())
for (Member m : p)
System.out.println(m.getCaption());
}
} |