Re: [Ramadda-users] Connecting to multiple database types
Brought to you by:
donmurray,
jmcwhirter
|
From: Jeff M. <jef...@gm...> - 2015-07-29 13:41:57
|
Hi Scott,
I've made the fix and seems to work in my test environment.
SourceForge file upload is down right now but if you SVN the latest and
build from source you should be OK
A caveat - the database integration is pretty new and somewhat buggy and/or
limited functionality. I'd like to build out this facility so if you find
it useful and have ideas for new functionality please share
-Jeff
-Jeff
On Tue, Jul 28, 2015 at 1:22 AM, Scott Wales <sco...@un...>
wrote:
> Hi Ramadda users,
>
> We've been running into some trouble trying to create links to a MySQL
> database using the 'Database Table' type. From what I can tell Ramadda will
> only set up the JDBC driver when connecting to its main database, not for
> external tables. Since our Ramadda DB is using Postgres, only the Postgres
> driver is loaded and we get an error when setting up the Database Table:
>
> java.sql.SQLException: No suitable driver found for
> jdbc:mysql://xx.xx.xx.xx/table
>
> The patch below changes the DB manager to load the driver both for the
> main database and external connections. Initial testing shows that this
> works, however I'm not familiar enough with server-side Java to know if
> loading the driver for every external connection would have a performance
> impact.
>
> Is there a better way to handle connecting to multiple database types?
>
> Cheers, Scott
>
> --
>
> Index: src/org/ramadda/repository/database/DatabaseManager.java
> ===================================================================
> --- src/org/ramadda/repository/database/DatabaseManager.java (revision
> 5793)
> +++ src/org/ramadda/repository/database/DatabaseManager.java (working
> copy)
> @@ -362,7 +362,22 @@
> "Could not determine database type:" + jdbc);
> }
>
> + /**
> + * Load the JDBC driver for `dbType`
> + */
> + private void loadDriver(String dbType) {
> + String propertyName = PROP_DB_DRIVER.replace("${db}", dbType);
> + String className = (String)
> getRepository().getProperty(propertyName);
>
> + try {
> + Class.forName(className);
> + }
> + catch (ClassNotFoundException e) {
> + System.err.println("Could not find JDBC driver for "+dbType);
> + }
> + }
> +
> +
> /**
> * _more_
> *
> @@ -378,14 +393,8 @@
> String userName, String
> password)
> throws Exception {
> String dbType = getDbType(connectionUrl);
> - String driverClassPropertyName = PROP_DB_DRIVER.replace("${db}",
> - dbType);
> - // System.err.println("JDBC Property:" +
> driverClassPropertyName);
> - String driverClassName =
> - (String) getRepository().getProperty(driverClassPropertyName);
> + loadDriver(dbType);
>
> - Misc.findClass(driverClassName);
> -
> BasicDataSource ds = new BasicDataSource();
>
>
> @@ -404,7 +413,6 @@
> // System.err.println("DatabaseManager.makeDataSource:
> url=" + connectionUrl);
> // System.err.println("JDBC driver class:" +
> driverClassName + " db type:" + dbType);
>
> - ds.setDriverClassName(driverClassName);
> ds.setUsername(userName);
> ds.setPassword(password);
> ds.setUrl(connectionURL);
> @@ -437,6 +445,10 @@
> public Connection getExternalConnection(String prefix) throws
> Exception {
> String connectionURL = getRepository().getProperty(prefix +
> ".url",
> (String) null);
> +
> + String dbType = getDbType(connectionURL);
> + loadDriver(dbType);
> +
> String user = getRepository().getProperty(prefix + ".user",
> (String) null);
> String password = getRepository().getProperty(prefix +
> ".password",
>
>
> --
> Scott Wales, Computational Modelling Systems
> ARC Centre of Excellence For Climate Systems Science
> School of Earth Sciences, The University of Melbourne, Australia 3010
> sco...@un... / P +61 3 8344 6907 / M 0450 012 907
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Ramadda-users mailing list
> Ram...@li...
> https://lists.sourceforge.net/lists/listinfo/ramadda-users
>
|