如何使用org.hsqldb.jdbc.JDBCConnection class HSQLDB API

How to use org.hsqldb.jdbc.JDBCConnection class of HSQLDB API

我知道在以编程方式创建 hsqldb 服务器时使用 org.hsqldb.server.Server class 很有用。

我一直都是用javaSDKclass(java.sql.Connection)连接服务器,感觉不管服务器是内存的还是文件的都能连接.

为什么我们需要 org.hsqldb.jdbc.JDBCConnection class 的 hsqldb API?

我使用 HSQLDB 的次数不多,但是 API 文档似乎是您问题的最佳来源。

Class JDBCConnection 的文档说 -

JDBC 4.0 Notes:

Starting with JDBC 4.0 (JDK 1.6), the DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. When built under a Java runtime that supports JDBC 4.0, HSQLDB distribution jars containing the Driver implementation also include the file META-INF/services/java.sql.Driver. This file contains the fully qualified class name ('org.hsqldb.jdbc.JDBCDriver') of the HSQLDB implementation of java.sql.Driver.

Hence, under JDBC 4.0 or greater, applications no longer need to explicitly load the HSQLDB JDBC driver using Class.forName(). Of course, existing programs which do load JDBC drivers using Class.forName() will continue to work without modification.

所以我想您可以继续使用标准化代码。

这个 class 可能有一些特定于 HSQLDB 的附加方法。

此外,如果计划使用这些特定方法,则必须进行类型转换,

JDBCConnection connection =
            (JDBCConnection) DriverManager.getConnection(url, connProperties);

关于您的其他问题,模式是 - <url>[;key=value]* 即您在 url 之后放置一个分号,然后以 key=value 格式指定键值。每个 key=value 需要用分号分隔。

例如jdbc:hsqldb:hsql://localhost/cities;user=bill;password=password 即在附加键值对之前添加分号,最后一个键值对不添加分号。

没有'class' java.sql.Connection:是一个接口。 JDBC 是一个 API,由接口(和一些支持 类)组成。这些接口需要由每个 JDBC 驱动程序实现才能真正执行任何操作。

当您使用 HSQLDB 时,您使用它的 java.sql.Connection 实现称为 org.hsqldb.jdbc.JDBCConnection;这包含 HSQLDB 如何工作的细节(JDBC 本身不知道的东西)。但是通常你只需要通过JDBC中定义的接口访问它;这对于便携性来说甚至更可取。

简而言之,如果不是 org.hsqldb.jdbc.JDBCConnection,您甚至无法连接到 HSQLDB。