简体   繁体   English

如何在我的Java项目中实现UnityJDBC?

[英]How do I implement the UnityJDBC in my Java project?

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). 我正在研究一个项目,它的全部内容都是从不同供应商的多个数据库中查询数据(我的意思是使用一个查询语句同时查询mysql,hsqldb,microsoft sql,oracle等数据库)。 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. 我遇到了这个unityjdbc软件,一个中介软件,但不知道如何在我的java源文件中实现它,以实现我的目标。 I have read the unityjdbc user manual but is not clear and straight-forward. 我已阅读了unityjdbc用户手册,但不清楚直截了当。 Please can anyone advise how toimplement this unityjdbc driver in my java application and use it to successful query multiple databases. 请任何人都可以建议如何在我的java应用程序中实现这个unityjdbc驱动程序,并使用它来成功查询多个数据库。 Suggestions for any other way to simultaneously query their multiple databases with a single statement would also be welcome. 对于使用单个语句同时查询其多个数据库的任何其他方式的建议也是受欢迎的。

UnityJDBC allows you to query multiple databases in one SQL query. UnityJDBC允许您在一个SQL查询中查询多个数据库。 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. 您不能使用单独的线程执行此操作,因为您将负责在Java程序中自己合并来自多个数据库的数据。

The setup steps are easy: 设置步骤很简单:

  1. Use the SourceBuilder application to specify the JDBC connection information to your databases. 使用SourceBuilder应用程序指定数据库的JDBC连接信息。

  2. Test a sample query that accesses multiple databases. 测试访问多个数据库的示例查询。 Standard SQL is supported. 支持标准SQL。 To reference tables in different databases use databaseName.tableName in your FROM clause. 要引用不同数据库中的表,请在FROM子句中使用databaseName.tableName
    For example: 例如:

    SELECT * FROM Database1.Table1 T1 INNER JOIN Database2.Table2 T2 ON T1.id = T2.id 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. SourceBuilder应用程序将提供XML配置文件作为输出,通常称为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. 要在您自己的Java程序或任何支持JDBC的软件中使用它,连接URL为: jdbc:unity://sources.xml您可以指定sources.xml文件的绝对路径或相对路径。

There is documentation on their site at http://www.unityjdbc.com/support/ or contact them for free support. 他们的网站上有文档,网址为http://www.unityjdbc.com/support/,或者联系他们获取免费支持。

Another way to get started quickly is to use the MultiSource SQL Plugin that comes with the open source query software SQuirreL SQL. 另一种快速入门的方法是使用开源查询软件SQuirreL SQL附带的MultiSource 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. 该插件允许您使用SQuirreL中的SQL查询任意数量的数据库,并将生成XML配置文件供您在其他程序中使用。 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. 该插件还支持使用MySQL和Postgres等关系数据库查询和加入像MongoDB这样的NoSQL数据库。

You don't need UnityJDBC for what you want to do, if you've already managed to load all the db-specific JDBC drivers. 如果您已经设法加载所有特定于db的JDBC驱动程序,则不需要UnityJDBC来执行您想要的操作。

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. 这样,在查询下一个数据库之前,您无需等待一个数据库返回其结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM