Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 597
John Avatar asked Feb 16 '23 20:02

John


1 Answers

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.

like image 104
Sridhar Pujekar Avatar answered Feb 18 '23 10:02

Sridhar Pujekar