-1

I'm trying to make a program that connects to an Oracle database for the ultimate purpose of creating a few tables and running commands on them for a course I am taking. I'm currently trying to make the example given in class work but I can't get that to work. The code that generates the error "java.lang.ClassNotFoundException" is when my main hits the code:

Class.forName("oracle.jdbc.OracleDriver");

or

Class.forName("oracle.jdbc.driver.OracleDriver");

I have manually added the ojdbc6.jar, ojdbc8.jar and ojdbc14.jar files to each folder in my "PATH" system variable and I'm getting the exception:

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

or 

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

I have no idea how to fix this or what to modify. It is a course example after all... Any/All suggestions are welcome.

Thank you for your time

  • Do you mean classpath? As far as I know, adding it to the system variable `PATH` won't help. – cegredev Apr 04 '20 at 17:59
  • `I have manually added the ojdbc6.jar, ojdbc8.jar and ojdbc14.jar files to each folder in my "PATH"` - that's wrong. You need to put it into classpath. How you run your application? – rkosegi Apr 04 '20 at 18:00
  • You shouldn't have to call `Class.forName()` to create a JDBC connection to Oracle. Just create the JDBC connection string and us that. See https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html – wilx Apr 04 '20 at 18:04

1 Answers1

-1

I hope this might help?

I don't think you need Class.forName with latest version.

I would have done something like below and set connection,url,user and password as global final variables to avoid repeating yourself and call the method where you need it.

 public Connection getConnection() throws SQLException {
    return connection = DriverManager.getConnection(url, user, password);

}
deniscns
  • 27
  • 4