使用JDBC连接来自同一服务器上不同数据库中2个Oracle表的数据 [英] Join data from 2 Oracle tables located in different database on the same server using JDBC

查看:327
本文介绍了使用JDBC连接来自同一服务器上不同数据库中2个Oracle表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Oracle数据库中有一个简单的表,该表需要与另一个Oracle数据库中的一组表结合在一起.它们驻留在同一服务器上(不同的端口).我正在使用JDBC,并希望保持简单.我可以连接到两个数据库,并以Java形式加入结果集.但我想知道是否有更好/更简便的方法.

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.

由于我在严格的公司环境中工作,因此我不能轻易使用新工具或框架,因此想知道是否可以仅使用JDBC来实现.

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.

推荐答案

无法在纯JDBC中实现,但是您可以使用oracle databaselink工具.它使一个数据库中的表在另一个数据库中可用,从而使您可以像在同一数据库中一样执行联接等. JDBC可以很好地与受这些链接约束的表一起使用.

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.

设置它们是一项管理功能,因此您需要DBA的参与.

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

除此之外,如果一个"表不太大,您可能必须将其读取到Map,然后在您的代码中对查询的连接部分进行操作(不理想)

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 )

这篇关于使用JDBC连接来自同一服务器上不同数据库中2个Oracle表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆