0

When I connect to the OracleDriver in the application, everything is fine. But when I want to connect to run the JUnit Tests, I got a ClassNotFoundException. And I do exactly the same!

I have the ojbc added to the library and the testlibrary.

    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);
}
Lennart
  • 1
  • 1

2 Answers2

0

Check for two things

  1. That rb.getString("driver") actually returns the FQCN of your driver.
  2. That the driver JAR is in classpath of your test application
adarshr
  • 61,315
  • 23
  • 138
  • 167
0

Try adding the Oracle JDBC driver jarfile to the classpath of the JUnit test. If you're running the unit test in Eclipse, add the driver jarfile to the User Entries in the Run Configuration of the JUnit test.

Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
  • I'm running the test in NetBeans. I've added the ojdbc.jar in the Test Libraries. I don't know what's going wrong... – Lennart Apr 06 '11 at 16:02
  • What class does the JVM complain that it cannot find? Does its name match the string which `rb.getString("driver")` returns? Is this the same as the driver class name? – Derek Mahar Apr 06 '11 at 16:14
  • @DerekMahar I have this in my properties: driver: oracle.jdbc.OracleDriver, and he finds it. It's like he doesn't find the jar file... – Lennart Apr 06 '11 at 17:45
  • Are you sure that this is the correct class name? Use JFind (http://jfind.sourceforge.net/) to search the Oracle JDBC driver jarfile for the class. – Derek Mahar Apr 06 '11 at 17:57
  • What is the value of your JVM classpath and what is the full path name of the Oracle JDBC driver jarfile? – Derek Mahar Apr 06 '11 at 17:59