3

Basically I need to run the following query through jdbc. Both databases are MySQL and on the same server.

SELECT * FROM DB1.ACCOUNT a
JOIN DB2.ITEM i ON a.AccountID = i.AccountID

My jdbc connection is set up like this:

Class.forName("com.mysql.jdbc.Driver").newInstance();
DB1 = DriverManager.getConnection("jdbc:mysql://serverloc.com:3300/DB1", "username", "password");
DB2 = DriverManager.getConnection("jdbc:mysql://serverloc.com:3300/DB2", "username", "password");

This is where I run into problems. I can now create a statement against DB1 or DB2, but I can't find a way to JOIN against both databases. I've tried running my query against one of the databases (below) but that returns null.

Statement statement = DB1.createStatement();
ResultSet resultSet = statement.executeQuery(" QUERY HERE ");

I've seen that you can use UnityJDBC to run JOIN queries across DB's, but I'm looking for a free/open source option.

Thanks!

1 Answer 1

4

1) Yes, you can "join" between two different databases in mySQL.

2) No, you don't need two different connections to do it.

For example:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.