当前位置: 代码迷 >> Eclipse >> java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
  详细解决方案

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

热度:15   发布时间:2016-04-23 14:09:45.0
DAO下做数据库的增删改查老是报错。求亲们解释。
java.lang.ClassNotFoundException: oracle.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 DBH.DBHelper.getConnection(DBHelper.java:21)
at DAOImpl.GradeDAOImpl.<init>(GradeDAOImpl.java:8)
at DaoFactory.DAOFactory.getGradeDAO(DAOFactory.java:10)
at Test.Test.main(Test.java:10)
Exception in thread "main" java.lang.NullPointerException
at DBH.DBHelper.rollback(DBHelper.java:138)
at DAOImpl.GradeDAOImpl.add(GradeDAOImpl.java:29)
at Test.Test.main(Test.java:11)
这是我运行出项的错误信息。
以下是我DBHelper的代码:
package DBH;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBHelper 
{
private static final String driver = "oracle.jdbc.driver.OracleDriver";
private static final String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
private static final String name = "hr";
private static final String password = "123456";

private static Connection conn;
public static Connection getConnection()
{
try
{
Class.forName(driver);
conn = DriverManager.getConnection(url, name, password);
} catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

return conn;
}

public static Statement getStatement(Connection conn)// 获得statement
{
Statement stmt = null;
try
{
if (conn != null)
{
stmt = conn.createStatement();
}
} catch (SQLException e)
{
e.printStackTrace();
}
return stmt;
}
public static ResultSet getResultSet(Statement stmt, String sql)// 获得数据库返回的记录集
{
ResultSet rs = null;
try
{
if (stmt != null)
{
rs = stmt.executeQuery(sql);
}
} catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}

public static int getInt(Statement stmt, String sql)
{
int i = 0;
try
{
i = stmt.executeUpdate(sql);
} catch (SQLException e)
{
e.printStackTrace();
}
return i;

}

public static void close(Connection conn)// 释放资源
{
try
{
if (conn != null)
{
conn.close();
conn = null;
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
public static void close(Statement stmt)
{
try
{
if (stmt != null)
{
stmt.close();
stmt = null;
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
public static void close(ResultSet rs)
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
public static void commit(Connection conn)// 功能是提交事务
{
try
{
conn.commit();
System.out.println("提交成功!");
} catch (SQLException e)
{
e.printStackTrace();
}
}
public static void rollback(Connection conn)// 功能是回滚事务
  相关解决方案