java - 在没有 Class.forName 的情况下加载 JDBC 驱动程序

标签 java jdbc

Oracle JDBC tutorial

In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method Class.forName. This methods required an object of type java.sql.Driver. Each JDBC driver contains one or more classes that implements the interface java.sql.Driver. The drivers for Java DB are org.apache.derby.jdbc.EmbeddedDriver and org.apache.derby.jdbc.ClientDriver, and the one for MySQL Connector/J is com.mysql.jdbc.Driver. See the documentation of your DBMS driver to obtain the name of the class that implements the interface java.sql.Driver.

Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)

但是当我删除 Class.forName 时,它给出了一个错误 No Driver found。我正在使用 ojdbc14 驱动程序。我们如何在没有 Class.forName 的情况下实现连接?

最佳答案

仔细查看 JDBC 版本。文章说它是在 JDBC 4.0 (Java 1.6) 中引入的。

但是,ojdbc14 是 JDBC 3.0 (Java 1.5) 驱动程序。

关于java - 在没有 Class.forName 的情况下加载 JDBC 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959202/

相关文章:

java - 不保存子实体

java - 尽管我将 jar 文件添加到类路径 (Eclipse),但为什么与 SQLite 的连接失败?

java - 使用dbf_jdbc问题写入dbf文件

java - 在 Soap Security Header (Spring WS) 中设置自定义标签

java - 对只读结果集 : updateString 的无效操作

java - 选择列并从其他选择中隐藏

java - 从一个Mysql数据库插入到另一个数据库

Java - 为什么我的按钮没有显示在面板中?

java - String.split() 不工作

java - 如何向用户显示可编辑的结果?