GBase 8a集群JDBC 通过Connection 获得GBase特有的连接参数hostList和gclusterId

通过URL,可以自行解析参数。也可以通过强制转换到GBase类型,获得各属性的值。

参数

hostList

高可用时,多个备用的gclusterd主机IP列表,用逗号分割。

gclusterId

唯一标识此连接URL的字符串,可自定义。如果你有多个URL,那么在【一个JVM】里一定要唯一,不能相同,否则这些IP会被当成1套集群使用。

开启负载均衡,每次连接,都按照round robin的循环的方式,返回使用的IP的连接。

failoverEnable

开启故障容错,每次连接,都从第一个IP开始尝试连接,直到连接成功。

样例

package gbase.sc;

import java.sql.Connection;
import java.sql.DriverManager;

public class Test {
	public static void main(String[] args) throws Exception {
		Connection con = DriverManager.getConnection(
				"jdbc:gbase://192.168.174.151:5258/information_schema?user=gbase&password=XXXXXXXXXXXX&failoverEnable=true&hostList=191.168.174.152,191.168.174.153&gclusterId=ZXvmax2017");
		System.out.println(con.getMetaData().getURL());
		com.gbase.jdbc.Connection c = (com.gbase.jdbc.Connection)con;
		System.out.println(c.getGclusterId());
		System.out.println(c.getHostList());		
	}
}

执行结果

jdbc:gbase://192.168.174.151:5258/information_schema?user=gbase&password=XXXXXXXXXXXX&failoverEnable=true&hostList=191.168.174.152,191.168.174.153&gclusterId=ZXvmax2017
ZXvmax2017
191.168.174.152