gpt4 book ai didi

java - 获取 JDBC 的 Solid 数据库的 URL

转载 作者:行者123 更新时间:2023-12-02 08:08:21 25 4
gpt4 key购买 nike

我有一个可靠的数据库。我想通过 JDBC 连接到这个数据库。如何获取用于创建连接的 URL?

[编辑]

欲了解更多信息: SOLID JDBC Driver Programmer's Guide

SOLID JDBC Driver 2.3 Readme

最佳答案

注册 JDBC 驱动程序

JDBC 驱动程序管理器完全用 Java 编写,负责处理加载和卸载驱动程序以及将连接请求与适当的驱动程序连接。 JavaSoft 的目的是使特定 JDBC 驱动程序的使用对程序员和用户尽可能透明。

驱动程序可以通过三种替代方式注册,如下所示。 Class.forName和Properties.put函数所需的参数是驱动程序的名称,即solid.jdbc.SolidDriver。

// registration using Class.forName service
Driver)Class.forName("solid.jdbc.SolidDriver")

// a workaround to a bug in some JDK1.1 implementations
Driver d = (Driver)Class.forName("solid.jdbc.SolidDriver").newInstance();

// Registration using system properties variable also
Properties p = System.getProperties();
p.put("jdbc.drivers", "solid.jdbc.SolidDriver");
System.setProperties(p);


连接到数据库

驱动程序成功注册到驱动程序管理器后,将通过使用以下代码创建 Java Connection 对象来建立连接。 DriverManager.getConnection函数所需的参数是JDBC连接字符串。

Connection conn = null;
try {
conn = DriverManager.getConnection(sCon);
}
catch (Exception e) {
System.out.println("Connect failed : " + e.getMessage());
throw new Exception("Halted.");
}

连接字符串结构为 jdbc:solid://://。字符串“jdbc:solid://fb9:1314/dba/dba”尝试连接机器 fb9 中的 SOLID 服务器,在端口 1314 监听 tcp/ip 协议(protocol)。

应用程序可以建立多个到数据库的Connection对象。可以通过以下代码关闭连接。

conn.close();

关于java - 获取 JDBC 的 Solid 数据库的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7805203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com