Reputation: 65
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");
}
}
Upvotes: 5
Views: 58125
Reputation: 71
You need to do following steps if you are using intellij
Upvotes: 1
Reputation: 1
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.
Upvotes: -3
Reputation: 6572
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());
}
}
}
Upvotes: 6
Reputation: 9456
You need to Add an oracle driver jar
to the project build path,
Download Ojdbc14.jar file and put it in your classpath.
Upvotes: 3