Joining tables in two mysql databases on different machines using JDBC or hibernate

Hi Experts,
We have two database on different machines, how we can join tables of different database(on different machine) in mysql using jdbc or hibernate
Detail:
1) I have two database servers i.e serverA and serverB
2) ServerA we have table productInfo
3) ServerB has order table
4) I need to join this two tables(i.e productInfo and order table) in mysql using jdbc or hibernate
5) Please provide standard solution
6) and also provide cons and pros

Thanks
vickytaurusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
Is the database user common across the two databases?
0
Kanti PrasadCommented:
Hi

The use should have access to both the DBs and tables.

SELECT *
FROM ServerB_DatabaseName.order
JOIN ServerA_DatabaseName.productInfo
     ON (ServerB_DatabaseName.order.your_order_field_ID = ServerA_DatabaseName.productInfo.your_productInfo_field_ID)
WHERE ServerA_DatabaseName.productInfo.columnIF = 100
0
dpearsonCommented:
Unless you have done something special to link the two servers (e.g. mounting the shared tables as network drives) I don't think you can do the join in the database.

Instead, you'd need to retrieve the data and do the join using code.

E.g. To join a specific order to product info, first retrieve the order, then find the product info id in the order and issue a second query to load that product info.  Then combine the two rows of data (again in code) and return that.

That's at least the JDBC approach.  No idea how Hibernate would do it.

Doug
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.