我尝试将我的Java应用程序连接到我的Oracle数据库,但我得到了这个异常
java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver at at java.net.URLClassLoader $ 1.run(未知来源)at java.net.URLClassLoader $ 1.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(未知来源)at java.lang.ClassLoader.loadClass(未知来源)at sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)at java.lang.ClassLoader.loadClass(未知来源)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(未知来源)at Com.getConnection(Com.java:11)在Main.main(Main.java:7)
并且有我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
public class Com {
public static Connection getConnection(){
Connection conn = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:orcl", "SH12", "121212");
}catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void closeConnection(Connection conn){
try{
if(conn != null){
if(!conn.isClosed()){
conn.close();
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
}