Skip to content

Register IoTDBDriver as a JDBC 4 service provider - #18744

Merged
HTHou merged 1 commit into
apache:masterfrom
PDGGK:feature/jdbc-driver-service-file
Sep 28, 2026
Merged

HTHou merged 1 commit into
apache:masterfrom
PDGGK:feature/jdbc-driver-service-file

Conversation

@PDGGK

@PDGGK PDGGK commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #18719, as discussed there.

Why

Since JDBC 4, DriverManager loads drivers through ServiceLoader from META-INF/services/java.sql.Driver, so an application can call DriverManager.getConnection("jdbc:iotdb://...") without first calling Class.forName. IoTDB's driver never took part in this. The file that existed before #18719 sat at services/META-INF/java.sql.Driver, with the directories in the wrong order, and its license header was a /* */ block, which provider files do not accept. Before #18719 a <resources> override in the jdbc pom also kept src/main/resources out of the jar. None of the released jars from 0.9.3 to 2.0.11 that I checked contain a provider file at either path, so every client has needed Class.forName("org.apache.iotdb.jdbc.IoTDBDriver").

Change

  • Add iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver naming org.apache.iotdb.jdbc.IoTDBDriver. The license header uses # comments, like the other provider files in the repo.
  • Add DriverServiceRegistrationTest. It asks ServiceLoader for java.sql.Driver providers and expects an IoTDBDriver among them. Going through ServiceLoader rather than DriverManager keeps the test independent of other tests that already loaded the driver class, which registers it as a side effect. The test is in a new file because Improve JDBC driver metadata #17865 adds IoTDBDriverTest.java.

Class.forName keeps working, and the CLI, which uses it, is unaffected. The only behaviour change is that DriverManager now finds the driver on its own.

Testing

  • The new test passes on a clean build. With the provider file removed, a clean build fails it with META-INF/services/java.sql.Driver should name IoTDBDriver. An incremental build hid that failure behind a stale copy in target/classes, so I checked this with clean.

  • The jdbc module's 74 tests and the 47 tests in the modules it depends on pass. spotless:check passes.

  • Against a running IoTDB 2.0.8, I ran a client that calls only DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", ...) and runs show version:

    classpath without Class.forName with Class.forName
    CLI lib/ built from this branch connects, returns 2.0.8 connects
    iotdb-jdbc-*-jar-with-dependencies.jar from this branch connects, returns 2.0.8 not run
    CLI lib/ built before this change No suitable driver found connects

Add META-INF/services/java.sql.Driver naming org.apache.iotdb.jdbc.IoTDBDriver,
so DriverManager finds the driver without a Class.forName call. The file that
existed before (at services/META-INF/, with a /* */ header ServiceLoader does
not accept) never took effect and was removed in apache#18719.

A unit test asks ServiceLoader for java.sql.Driver providers and expects
IoTDBDriver among them; it fails when the file is missing.

Signed-off-by: Zihan Dai <1436286758@qq.com>
@HTHou
HTHou merged commit 79631e3 into apache:master Sep 28, 2026
38 of 43 checks passed
VGalaxies pushed a commit to VGalaxies/iotdb that referenced this pull request Oct 26, 2026
Add META-INF/services/java.sql.Driver naming org.apache.iotdb.jdbc.IoTDBDriver,
so DriverManager finds the driver without a Class.forName call. The file that
existed before (at services/META-INF/, with a /* */ header ServiceLoader does
not accept) never took effect and was removed in apache#18719.

A unit test asks ServiceLoader for java.sql.Driver providers and expects
IoTDBDriver among them; it fails when the file is missing.

Signed-off-by: Zihan Dai <1436286758@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants