java jdbc url 中的两个主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17788085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Two hosts in jdbc url
提问by Dedyshka
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!
我们正在使用 jdbc url,如jdbc:mysql://localhost:3306/mysql
. 我怎么能在这个 url 中设置第二个 mysql 主机?如果这是不可能的,我如何在我的 Java 应用程序(休眠)中设置到第二个 MySQL 服务器的连接?谢谢!
PS. actually we want to parallelize operations to two different databases. Is there any solution for that in Hibernate?
附注。实际上,我们希望将操作并行化到两个不同的数据库。在 Hibernate 中有什么解决方案吗?
回答by mujib ishola
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
jdbc:mysql://192.168.29.20:3306,192.168.29.20:6306/mysql 应该这样做。见http://lists.mysql.com/cluster/249
Reference:
参考:
回答by smillien62
an example for Oracle (failover with 3 hosts):
Oracle 示例(具有 3 个主机的故障转移):
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)))
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.
问候。
回答by Shreyash
2 options here:
这里有2个选项:
1) You can write some code which would change your hibernate properties and switch your DB url.
1)您可以编写一些代码来更改您的休眠属性并切换您的数据库网址。
2) you can have multiple hibernate configurations for multiple session-factories.
2)您可以为多个会话工厂设置多个休眠配置。