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

点点圈 提交于 2020-03-19 02:27:42

问题


I want to connect to database in java web application.I wrote this code in servlet and i add related jar file(ojdbc) but when i run it,it gives me this error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

public class DBConnection extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public DBConnection() {
        super();
        // TODO Auto-generated constructor stub
    }

    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        Connection con = null;  

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
              con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.101.84:1521:orcl","XXXX","XXXX");
              if(con!=null)
                 System. out.println("Connection Successful");
              else
                  System.  out.println("error");

        }
        catch (Exception e) {
            //System.out.println(e);
        }
...

what should i do?


回答1:


I was having the same issue. What you need is to include the ojdbc6.jar file in the Deployment Assembly of the Project:

  1. Right click on the project
  2. select "Properties"
  3. Select "Deployment Assembly" tab
  4. Add your ojdbc6.jar file in it..

...and the problem is solved.




回答2:


You can try this by adding your jar of oracle driver into classpath environment variable just for testing purpose. or you can also load it at runtime by supplying the library into endorsed directory of your server (TOMCAT) otherwise you can copy your library file into common lib of your application server . It's just related to the oracle driver library which is not loading at startup of your application..




回答3:


I have faced the same problem but got it fixed Right click on the project->properties and add your jar(ojdbc6 or 14) file in the deployment assembly then it will work...




回答4:


I was having the same issue and what you need is

You must include the ojdbc6.jar file in the Deployment Assembly of the Project.......

1)Right click on the project

2)select "Properties"

3)Select "Deployment Assembly" tab

4)Add your ojdbc6.jar file in it..

and the problem solve.



来源:https://stackoverflow.com/questions/17803818/error-java-lang-classnotfoundexception-oracle-jdbc-driver-oracledriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!