Reputation: 107
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver
Goodbye!
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at JDBC.main(JDBC.java:21)
import java.sql.*;
public class JDBC {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
Open a connection
try{
Class.forName("com.oracle.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection
("jdbc:oracle:thin:@172.16.209.169:1521:heritage", "USERNAME", "PASSWORD");
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
Handle errors for Class.forName
e.printStackTrace();
}finally{
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
Upvotes: 0
Views: 745
Reputation: 8657
You need to add JDBC driver to your class path.
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver // this error shows that your application is missing oracle jdbc driver.
Download Oracle jdbc driver, then add it to your class path.
Upvotes: 2