4

We are using jdbc url like jdbc:mysql://localhost:3306/mysql. How could I set second mysql host in this url? If this is imposible, how could I set in my java application (hibernate) connection to second MySQL server? Thanks!

PS. actually we want to parallelize operations to two different databases. Is there any solution for that in Hibernate?

3 Answers 3

11

an example for Oracle (failover with 3 hosts):

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.200.40.5)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.200.40.6)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.200.40.7)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=OLTP.WORLD)))

Regards.

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

1 Comment

,what will be the order of connection in above jdbc url?
9

This is really about failover/clustering.

jdbc:mysql://192.168.29.20:3306,192.168.29.20:6306/mysql should do it. see http://lists.mysql.com/cluster/249

Reference:

2 Comments

There is some delay when first server is down. When application tries to connect to second connection I have a delay few seconds. (FYI I have the same two mysql servers on the same machine on different ports 3306 & 3307). Do you know where is the problem?
That is understandable.The url doesn't mean you have two connection established and the fail over code only kicks in when there is a problem with the first connection.The delay could also depends on what you are trying to do "Transactions comes to mind here" and all and how you have managed exceptions.
0

2 options here:

1) You can write some code which would change your hibernate properties and switch your DB url.

2) you can have multiple hibernate configurations for multiple session-factories.

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.