Derby EmbeddedDriver 在没有 Class.forName 的情况下工作
Derby EmbeddedDriver working without Class.forName
文档告诉我们像这样加载 JDBC 驱动程序
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
https://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
但它在没有直接连接的情况下工作正常
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
这是为什么?
来自日志的版本:启动 Derby 版本 Apache 软件基金会 - Apache Derby - 10.13.1.1 - (1765088)
编辑:
实际上,如果您关闭 Derby 引擎并想在同一个 JWM 进程中再次打开它(我在集成测试中一直这样做)
关机后
DriverManager.getConnection("jdbc:derby:;shutdown=true");
你应该像这样重新打开
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:
my.sql.Driver
Applications no longer need to explicitly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.
文档告诉我们像这样加载 JDBC 驱动程序
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
https://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
但它在没有直接连接的情况下工作正常
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
这是为什么?
来自日志的版本:启动 Derby 版本 Apache 软件基金会 - Apache Derby - 10.13.1.1 - (1765088)
编辑:
实际上,如果您关闭 Derby 引擎并想在同一个 JWM 进程中再次打开它(我在集成测试中一直这样做)
关机后
DriverManager.getConnection("jdbc:derby:;shutdown=true");
你应该像这样重新打开
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:
my.sql.Driver
Applications no longer need to explicitly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.