GBase 8s
运维管理
文章

使用JDBC获取GBase8s数据库连接(二)

发表于2025-12-17 10:21:5343次浏览2个评论

方法二

在方法一的基础上添加数据库配置文件,让连接GBase8s更加灵活

    @Test
    public void connect02() throws IOException, ClassNotFoundException, SQLException {
        //通过properties对象获取配置文件的信息
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\GBase.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");

        //jdbc驱动加载
        Class.forName(driver);
        //连接数据库
        Connection connection = DriverManager.getConnection(url, user, password);
        System.out.println("方式2连接数据库:" + connection);

    }

GBase.properties配置文件内容如下

#单实例连接或者连接集群中的主节点
driver=com.gbasedbt.jdbc.Driver
url=jdbc:gbasedbt-sqli://192.168.31.177:9088/gbkdb:GBASEDBTSERVER=gbase01;DB_LOCALE=zh_CN.57372;IFX_USEPUT=1;ifx_lock_mode_wait=60
user=gbasedbt
password=GBase123
#集群连接方式
driver=com.gbasedbt.jdbc.Driver
url=jdbc:gbasedbt-sqli:/gbkdb:GBASEDBTSERVER=db_group;SQLH_TYPE=FILE;SQLH_FILE=D:\\BaiduNetdiskDownload\\sqlhosts;DB_LOCALE=zh_CN.57372;CLIENT_LOCALE=zh_CN.57372;ifx_lock_mode_wait=60
user=gbasedbt
password=GBase123

评论

登录后才可以发表评论
xinyiedc!发表于 2个月前
学会了
茵陈发表于 2个月前
加油