0

当我连接到应用程序中的 OracleDriver 时,一切都很好。但是当我想连接运行 JUnit 测试时,我得到了 ClassNotFoundException。我做的完全一样!

我已将 ojbc 添加到库和测试库中。

    public JDBCDataStorage(boolean production) throws DataStorageException {
    this.production = production;
    try {
        rb = (PropertyResourceBundle) PropertyResourceBundle.getBundle("app.control.database.JDBCconfig");

            Class.forName(rb.getString("driver"));




    } catch (ClassNotFoundException e) {
        throw new DataStorageException("Something went wrong in new JDBCDataStorage()" + ": " + e.getMessage());
    }

    DriverManager.setLoginTimeout(3);
}
4

2 回答 2

0

检查两件事

  1. rb.getString("driver")实际上返回了您的驱动程序的 FQCN。
  2. 驱动程序 JAR 在您的测试应用程序的类路径中
于 2011-04-06T15:53:20.770 回答
0

尝试将 Oracle JDBC 驱动程序 jarfile 添加到 JUnit 测试的类路径中。如果您在 Eclipse 中运行单元测试,请将驱动程序 jarfile 添加到 JUnit 测试的运行配置中的用户条目中。

于 2011-04-06T15:55:45.403 回答