Join data from 2 Oracle tables located in different database on the same server using JDBC

前提是你 提交于 2019-12-13 08:53:54

问题


I have one simple table in one Oracle database that needs to be joined with a group of tables in another Oracle database. They reside on the same server (different ports). I am using JDBC and want to keep it simple. I could connect to both DBs and join the result sets in Java. But I am wondering if there is a better/easier way.

I cannot easily use new tools or frameworks since I work in the rigid corporate environment, so want to know if it can be accomplished with just JDBC.


回答1:


No way to do it in pure JDBC as far as I am aware, but you could use the oracle databaselink facility. It makes the tables from one database available in another, allowing you to carry out joins etc as if they were in the same database. JDBC will work nicely with tables that are subject to these links.

Setting them up is an administrative function, so you'll need some DBA involvement.

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm

Other than that, if the "one" table isn't too big, you may have to read that to a Map and then peform the join parts of the query in your code ( which is not ideal )




回答2:


I see two options.

  1. Get the data from two datasources manually and then combine it(which you have already thought about).
  2. Create a db link from one database to other database and create a synonym in your schema for the remote object and directly execute the sql statement with joins from java.


来源:https://stackoverflow.com/questions/18896524/join-data-from-2-oracle-tables-located-in-different-database-on-the-same-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!