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;
打开连接
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){
处理Class.forName的错误
e.printStackTrace();
}finally{
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
答案 0 :(得分:2)
您需要将JDBC驱动程序添加到类路径中。
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver // this error shows that your application is missing oracle jdbc driver.
下载Oracle jdbc driver,然后将其添加到您的类路径中。
答案 1 :(得分:1)
您的ojdbc $ version.jar似乎不在类路径中。