Repository navigation
Register IoTDBDriver as a JDBC 4 service provider - #18744
Merged
Merged
Conversation
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
approved these changes
Sep 28, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #18719, as discussed there.
Why
Since JDBC 4,
DriverManagerloads drivers throughServiceLoaderfromMETA-INF/services/java.sql.Driver, so an application can callDriverManager.getConnection("jdbc:iotdb://...")without first callingClass.forName. IoTDB's driver never took part in this. The file that existed before #18719 sat atservices/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 keptsrc/main/resourcesout 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 neededClass.forName("org.apache.iotdb.jdbc.IoTDBDriver").Change
iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Drivernamingorg.apache.iotdb.jdbc.IoTDBDriver. The license header uses#comments, like the other provider files in the repo.DriverServiceRegistrationTest. It asksServiceLoaderforjava.sql.Driverproviders and expects anIoTDBDriveramong them. Going throughServiceLoaderrather thanDriverManagerkeeps 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 addsIoTDBDriverTest.java.Class.forNamekeeps working, and the CLI, which uses it, is unaffected. The only behaviour change is thatDriverManagernow 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 intarget/classes, so I checked this withclean.The jdbc module's 74 tests and the 47 tests in the modules it depends on pass.
spotless:checkpasses.Against a running IoTDB 2.0.8, I ran a client that calls only
DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", ...)and runsshow version:Class.forNameClass.forNamelib/built from this branch2.0.8iotdb-jdbc-*-jar-with-dependencies.jarfrom this branch2.0.8lib/built before this changeNo suitable driver found