View Full Version : How to obtain connection in standalone app

10-02-2003, 07:11 AM
What's the correct way to obtain a mondrian.olap.Connection in a standalone application? I have tried the following, but it hangs indefinitely on calling the getCollection method:
Connection connection = DriverManager.getConnection("Provider=mondrian;" +
"Jdbc=jdbc:mysql://localhost/foodmart?user=foodmart&password=foodmart;" +
"Catalog=http://localhost:8080/FoodMart.xml;JdbcDrivers=com.mysql.jdbc.Driver;", null, true);
System.out.println("Connected"); // never get here!
Also, is there a way to have the catalog file loaded from the classpath? Having to access it from a web server seems a bit awkward for an application that does not itself make use of a web server.

10-02-2003, 08:02 AM
The Catalog string can be:
This makes things look on the classpath.

10-03-2003, 01:21 AM
If I specify Catalog=/FoodMart.xml (or /WEB-INF/queries/FoodMart.xml), I get the following exception:
java.net.MalformedURLException: no protocol: /FoodMart.xml
at java.net.URL.<init>(URL.java:537)
at java.net.URL.<init>(URL.java:434)
at java.net.URL.<init>(URL.java:383)
at mondrian.rolap.RolapSchema.<init>(RolapSchema.java:87)
Before the exception is thrown, there is the following output:
Mondrian: JDBC driver com.mysql.jdbc.Driver loaded successfully
Mondrian: Warning: file 'C:\Projects\Log\mondrian.properties' not found
Mondrian: loaded 0 system properties
Mondrian: JDBC driver sun.jdbc.odbc.JdbcOdbcDriver loaded successfully
Mondrian: Warning: JDBC driver org.hsqldb.jdbcDriver not found
Mondrian: Warning: JDBC driver oracle.jdbc.OracleDriver not found
Has anyone been able to get Mondrian working outside of a servlet?
In any case, even if I start up a web server and specify Catalog=http://localhost:8080/FoodMart.xml
mondran.olap.DriverManager.getConnection() hangs here:
Thread [main] (Suspended)
GenericObjectPool.borrowObject() line: not available [local variables unavailable]
PoolingDataSource.getConnection() line: 110
SqlMemberSource.getLevelMemberCount(RolapLevel) line: 97
SqlMemberSource.getMemberCount() line: 81
RolapSchema.createMemberReader(RolapHierarchy, MondrianDef$Hierarchy) line: 399
RolapSchema.createMemberReader(String, RolapHierarchy, MondrianDef$Hierarchy) line: 338
RolapHierarchy.init(RolapCube) line: 131
RolapDimension.init(RolapCube) line: 119
RolapCube.init() line: 174
RolapCube.<init>(RolapSchema, MondrianDef$Schema, MondrianDef$Cube) line: 76
RolapSchema.load(MondrianDef$Schema) line: 115
RolapSchema.<init>(String, Util$PropertyList) line: 93
RolapSchema.<init>(String, Util$PropertyList, RolapSchema$1) line: 34
RolapSchema$Pool.get(String, String, String, String, Util$PropertyList) line: 249
RolapConnection.<init>(Util$PropertyList, RolapSchema) line: 89
RolapConnection.<init>(Util$PropertyList) line: 60
DriverManager.getConnection(Util$PropertyList, ServletContext, boolean) line: 133
DriverManager.getConnection(String, ServletContext, boolean) line: 49
Olap.main(String[]) line: 12
Any ideas?

10-04-2003, 05:46 AM
I think you have to provide a complete absolute URL to the Schema file.
should work if you have deployed a FoodMart.xml there. Else try something like

10-04-2003, 07:27 AM
syntax works. I had tried this previously but only with two slashes... Anyways, I must say that neither option is very practical when writing applications that may be deployed anywhere. I wonder how difficult it would be for Mondrian to try to load the schema file from the classpath, if a relative location is specified?

10-04-2003, 10:05 AM
You could do
String urlString = getClass().getResource("FoodMart.xml").toExternalForm();
and then use urlString to connect to Mondrian. The example assumes that FoodMart.xml is in the same package than the calling class (this).

10-05-2003, 08:51 PM
Thanks a lot, this.getClass().getResource("FoodMart.xml").toExternalForm() was exactely what I was looking for.