-1

I have two databases on the same server.

I want to show single result from two different databases when user search any term! how can we do this? I am using JSP

2
  • Well, to begin with you'll need to provide connections to both databases or else have a single view in one of them which includes data of the other DB. You really need to give some more info and what you have tried/thought of so far. Commented Jun 20, 2012 at 5:37
  • 1
    May this link help you -> stackoverflow.com/questions/1183341/… Commented Jun 20, 2012 at 5:42

1 Answer 1

3

You don't need to connect with both databases. Let me explain..

We have two databases DB_1 and DB_2, both has tables DB_1.Table1 and DB_2.Table2.

Assuming that DB_1 has more tables to use in. Here you just need to provide GRANT on Table2 of DB_2 to DB_1. OR You may provide grant for all tables of DB_2 (as per you need). This is the way Oracle behave. If your DB server do not support the same just give the permissions (GRANT) to your DB_1's user to use multiple tables of different database.

and the query will look like..

Select t1.id, t1.name,t2.id, t2.name t2 from DB_1.Table1 t1, DB_2.Table2 t2 where...

And as you wrote

I want to show single result from two different databases when user search any term!

your query will be..

Select t1.id, t1.name from DB_1.Table1 t1 where...
Union All
Select t2.id, t2.name from DB_2.Table2 t2 where...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.