Question

i have a project am working on, its all about querying a data from multiple databases from different vendors (i mean querying databases like mysql, hsqldb, microsoft sql, oracle, etc at the same time using one query statement). Though i have achieved this by loading each driver of the database connector sequentially and execute the query sequentially across the databases. But the project architecture is such that when i sent a query statement, it shouldgo simultaneously to each database and retrieve the item ifavailable in all databases involved. I came across this unityjdbc software, a mediation software but dont know how to implement it in my java source file so that to achieve my aim. I have read the unityjdbc user manual but is not clear and straight-forward. Please can anyone advise how toimplement this unityjdbc driver in my java application and use it to successful query multiple databases. Suggestions for any other way to simultaneously query their multiple databases with a single statement would also be welcome.

Was it helpful?

Solution

UnityJDBC allows you to query multiple databases in one SQL query. You cannot do this using separate threads as you would then be responsible for merging the data from the multiple databases yourself in your Java program.

The setup steps are easy:

  1. Use the SourceBuilder application to specify the JDBC connection information to your databases.

  2. Test a sample query that accesses multiple databases. Standard SQL is supported. To reference tables in different databases use databaseName.tableName in your FROM clause.
    For example:

    SELECT * FROM Database1.Table1 T1 INNER JOIN Database2.Table2 T2 ON T1.id = T2.id

  3. The SourceBuilder application will provide an XML configuration file as output often called sources.xml. To use this in your own Java program or any software that supports JDBC the connection URL is: jdbc:unity://sources.xml You may specify an absolute or relative path to the sources.xml file.

There is documentation on their site at http://www.unityjdbc.com/support/ or contact them for free support.

Another way to get started quickly is to use the MultiSource SQL Plugin that comes with the open source query software SQuirreL SQL. The plugin will allow you to query any number of databases using SQL in SQuirreL and will generate the XML configuration files for you to use in other programs. The plugin is open source and free. The plugin also supports querying and joining NoSQL databases like MongoDB with relational databases such as MySQL and Postgres.

OTHER TIPS

You don't need UnityJDBC for what you want to do, if you've already managed to load all the db-specific JDBC drivers.

Instead, you should look at doing each query in a separate thread. That way, you don't need to wait for one database to return its results before querying the next one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top