java.lang.ClassNotFoundException: orcale.jdbc.driver.oracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at util.DBHelper.<clinit>(DBHelper.java:17)
连接异常
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:ORCL
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at util.DBHelper.getConnection(DBHelper.java:25)
at util.DBHelper.main(DBHelper.java:33)
public class DBHelper {
private static final String URL="jdbc:oracle:thin:@localhost:1521:ORCL"; //连接数据库URL地址
private static final String USERNAME="scott"; //用户名
private static final String PASSWORD="tiger"; //密码
private static final String DRIVER="orcale.jdbc.driver.oracleDriver"; //加载数据库驱动
private static Connection conn=null;
//静态代码块,加载驱动
static{
try {
Class.forName(DRIVER);
} catch (Exception e) {
e.printStackTrace();
}
}
//单例模式,返回数据库连接
public static Connection getConnection()throws Exception{
if(conn==null){
conn=DriverManager.getConnection(URL, USERNAME, PASSWORD);
return conn;
}else{
return conn;
}
}
public static void main(String[] args) {
try {
Connection conn=DBHelper.getConnection();
if(conn!=null){
System.out.println("连接成功");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("连接异常");
}
}
“java.lang.ClassNotFoundException: orcale.jdbc.driver.oracleDriver”提示找不到Oracle数据库驱动程序。所以,检查一下是否在项目的lib目录导入了Oracle驱动程序jar包。