当前位置:编程学习 > JAVA >>

j2ee 加载oracle.jdbc.driver.OracleDriver 报错已经导入包了

报错信息:(试过换路径不管是tomcat 的目录还是项目的WEB-INF\lib 目录都运行不出来)
errordata
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at dao.StudentDao.initConnection(StudentDao.java:29)
at dao.StudentDao.queryStuByName(StudentDao.java:44)
at prj2_1.QueryAction.execute(QueryAction.java:37)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at dao.StudentDao.queryStuByName(StudentDao.java:45)
at prj2_1.QueryAction.execute(QueryAction.java:37)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
加载的包:下面test项目是可以成功连接数据库的



连接代码:
try{
/*
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:" + "thin:@127.0.0.1:1521:XE","osky","osky123");
 System.out.println("连接成功!");
 */
System.out.println("开始尝试连接数据库!BBBB");
 Class.forName("oracle.jdbc.driver.OracleDriver");// 加载Oracle驱动程序
 System.out.println("开始尝试连接数据库!BBBB");
    System.out.println("开始尝试连接数据库!");
    String url = "jdbc:oracle:" + "thin:@127.0.0.1:1521:XE";// 127.0.0.1是本机地址,XE是精简版Oracle的默认数据库名
    String user = "osky";// 用户名,系统默认的账户名
    String password = "osky123";// 你安装时选设置的密码
    conn = DriverManager.getConnection(url, user, password);// 获取连接
    System.out.println("连接成功!");
}catch(Exception ex){ System.out.println("errordata");ex.printStackTrace();}
}
--------------------编程问答-------------------- 那就用test 的包 --------------------编程问答-------------------- 你直接在代码中import oracle.jdbc.driver.OracleDriver看看你的编辑器是否报错。 --------------------编程问答-------------------- test 那个是普通的java 项目,报错那个是j2ee 项目。还是会报错 --------------------编程问答-------------------- 你确定你部署到服务器上的WEB-INF\lib有驱动包吗? --------------------编程问答-------------------- tomcat6下的lib文件夹得放oracle的驱动jar包 --------------------编程问答-------------------- 就是,你看看你发布到服务器下的lib下有没有相应的jar包 --------------------编程问答-------------------- 都加载过,还是不行。
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,