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");
}
}
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());
}
}
}
You need to Add an oracle driver jar to the project build path,
Download Ojdbc14.jar file and put it in your classpath.
You need to do following steps if you are using intellij
- Download jdbc7 or any version
- Add this jar on following path File>>Project Structure>>Libraries>> Image 1
- Click on Modules and add jar there too if you still face issue then you must see following problem Image 2
- 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.