Package Oracle. Jdbc. Driver Does Not Exist

Package Oracle. Jdbc. Driver Does Not Exist

Error in the following code ![error occured][1]

import java.sql.*;

public class DBConnect{
public static void main(String a[]) throws SQLException{
    // *package oracle.jdbc.driver does not exist*
    Driver d=new oracle.jdbc.driver.OracleDriver();
    DriverManager.registerDriver(d);
    System.out.println("Driver is registered");
    }
}
10

4 Answers

You have to add ocjdbc jar in to your class path and try it like this.

if your jar file and java source is in same location. Use a command prompt and changed directory to that location. and execute following

 javac -classpath ocjdbc14.jar DBConnect.java

and see.

import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class DBConnect{
 public static void main(String a[]) {
   try{
    Driver d=new OracleDriver();
    DriverManager.registerDriver(d);
    System.out.println("Driver is registered");
  }catch(SQLException e){
     System.out.println("Error occured "+e.getMessage());
     }
}
 }
3

You need to Add an oracle driver jar to the project build path,

Download Ojdbc14.jar file and put it in your classpath.

1

You need to do following steps if you are using intellij

  1. Download jdbc7 or any version
  2. Add this jar on following path File>>Project Structure>>Libraries>> Image 1
  3. Click on Modules and add jar there too if you still face issue then you must see following problem Image 2
  4. Now click on problems>>fix>>add to dependency as given below Image 3 Hope this will fix your issue

First run the program in netbeans and add Ojdbc14.jar file into the library of the program and then it will surely execute.

After executing in NetBeans, click Clean & Build Project.... This will create a jar file and then path like java -jar "C:\Users\s\Documents\NetBeansProjects\jdbcTest_course\dist\jdbcTest_course.jar" will be provided.

Enter this into a command prompt (cmd) and it will run.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.