java lang ClassNotFoundException oracle jdbc driver OracleDriver

0 votes

I am getting this exception when I run my  Java Servlet program:

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

My code:

package skypark;

import java.io.*;
import javax.servlet.*;
import java.text.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Date;

public class Registration extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public static Connection prepareConnection() throws ClassNotFoundException, SQLException {
        String dcn = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@JamesPJ-PC:1521:skypark";
        String usname = "system";
        String pass = "tiger";
        Class.forName(dcn);
        return DriverManager.getConnection(url, usname, pass);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        try {
            String phone1, dofb, date1, month, year, uname, fname, lname, address, city, state, country;
            String pin, email, password, gender, lang, qual, relegion, privacy, hobbies, fav;

            uname = req.getParameter("uname");
            fname = req.getParameter("fname");
            lname = req.getParameter("lname");
            date1 = req.getParameter("date");
            month = req.getParameter("month");
            year = req.getParameter("year");
            address = req.getParameter("address");
            city = req.getParameter("city");
            state = req.getParameter("state");
            country = req.getParameter("country");
            pin = req.getParameter("pin");
            email = req.getParameter("email");
            password = req.getParameter("password");
            gender = req.getParameter("gender");
            phone1 = req.getParameter("phone");

            lang = "";
            qual = "";
            relegion = "";
            privacy = "";
            hobbies = "";
            fav = "";

            dofb = date1 + "-" + month + "-" + year;
            int phone = Integer.parseInt(phone1);
            DateFormat formatter;
            java.util.Date dob;
            formatter = new SimpleDateFormat("dd-MM-yy");
            dob = formatter.parse(dofb);

            Connection con = prepareConnection();
            String Query = "Insert into regdetails values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement ps = con.prepareStatement(Query);

            ps.setString(1, uname);
            ps.setString(2, fname);
            ps.setString(3, lname);
            ps.setDate(4, (Date) dob);
            ps.setString(5, address);
            ps.setString(6, city);
            ps.setString(7, state);
            ps.setString(8, country);
            ps.setString(9, pin);
            ps.setString(10, lang);
            ps.setString(11, qual);
            ps.setString(12, relegion);
            ps.setString(13, privacy);
            ps.setString(14, hobbies);
            ps.setString(15, fav);
            ps.setString(16, gender);

            int c = ps.executeUpdate();

            String query = "insert into passmanager values(?,?,?,?)";
            PreparedStatement ps1 = con.prepareStatement(query);

            ps1.setString(1, uname);
            ps1.setString(2, password);
            ps1.setString(3, email);
            ps1.setInt(4, phone);

            int i = ps1.executeUpdate();

            if (c == 1 || c == Statement.SUCCESS_NO_INFO && i == 1 || i == Statement.SUCCESS_NO_INFO) {
                out.println("<html><head><title>Login</title></head><body>");
                out.println("<center><h2>Skypark.com</h2>");
                out.println("<table border=0><tr>");
                out.println("<td>UserName/E-Mail</td>");
                out.println("<form action=login method=post");
                out.println("<td><input type=text name=uname></td>");
                out.println("</tr><tr><td>Password</td>");
                out.println("<td><input type=password name=pass></td></tr></table>");
                out.println("<input type=submit value=Login>");
                out.println("</form></body></html>");
            } else {
                out.println("<html><head><title>Error!</title></head><body>");
                out.println("<center><b>Given details are incorrect</b>");
                out.println(" Please try again</center></body></html>");
                RequestDispatcher rd = req.getRequestDispatcher("registration.html");
                rd.include(req, resp);
                return;
            }
        } catch (ClassNotFoundException cnfe) {
            out.println("<html><head><title>Error!</title><body>");
            out.println("<b><i>Class not found " + cnfe + "</i></b>");
            out.println("</body></html>");
        } catch (SQLException sqle) {
            out.println("<html><head><title>Error!</title><body>");
            out.println("<b><i>Unable to process try after some time Sql error</i></b>");
            out.println("</body></html>");
        } catch (ParseException e) {
            out.println("<html><head><title>Error!</title><body>");
            out.println("<b><i>Unable to process Parseint exc " + e + "</i></b>");
            out.println("</body></html>");
        }

        out.flush();
        out.close();
    }
}

This is the class path: 

C: \Windows\ system32 > echo % classpath %
  E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ oui\ jlib\ classes12.jar;
E: \app\ JamesPJ\ product 11.2.0\ dbhome_1\ jlib\ orai18n.jar;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ jdbc\ lib\ ojdc6_g.jar;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ BIN;
C: \Program Files\ Java\ jdk1.7.0_09\ bin;
C: \Users\ JamesPJ\ Documents;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ jdbc\ lib;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ jlib;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ jdbc\ lib\ ojdbc6.jar;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ oc4j\ jdbc\ lib\ orai18n.jar;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ oc4j\ jdbc\ lib\ ocrs12.jar;
E: \app\ JamesPJ\ product\ 11.2.0\ dbhome_1\ owb\ wf\ lib\ ojdbc14.jar;
C: \Program Files\ Apache Software Foundation\ Tomcat 7.0\ lib\ servlet - api.jar

How can I solve this?

May 7, 2022 in Java by narikkadan
• 63,600 points
2,441 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
1 answer

java.lang.classnotfoundexception: com.mysql.jdbc.driver

I assume that your mysql connectivity library ...READ MORE

answered Feb 8, 2022 in Java by Soham
• 9,710 points
8,165 views
0 votes
0 answers

Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception

I am getting this exception when I ...READ MORE

May 18, 2022 in Java by Kichu
• 19,040 points
1,430 views
0 votes
2 answers

How can I solve java.lang.NoClassDefFoundError in Java?

NoClassDefFoundError means that the class is present ...READ MORE

answered Sep 11, 2018 in Java by Sushmita
• 6,920 points
34,093 views
0 votes
1 answer

How can we resolve ClassNotFoundException in Java?

Your classpath is broken. Depending on how you ...READ MORE

answered May 22, 2018 in Java by Akrati
• 3,190 points
1,235 views
0 votes
1 answer

java.lang.OutOfMemoryError: GC overhead limit exceeded Error

This simply means that for some reason ...READ MORE

answered May 31, 2018 in Java by misc.edu04
• 1,450 points
4,491 views
+1 vote
1 answer

How can we resolve java.lang.OutOfMemoryError in Java?

Work with smaller batches of HashMap Objects ...READ MORE

answered Jun 5, 2018 in Java by sharth
• 3,370 points
999 views
0 votes
1 answer

How to retrieve column names from java.sql.ResultSet?

You may refer the below code: ResultSet ...READ MORE

answered Jul 4, 2018 in Java by sophia
• 1,400 points
2,865 views
0 votes
1 answer

Establish JDBC Connection in R through single sign-on

You can certainly connect to databases with ...READ MORE

answered Sep 12, 2018 in AWS by Priyaj
• 58,020 points
2,478 views
0 votes
1 answer

Find Oracle JDBC driver in Maven repository

Download the jar and place it in ...READ MORE

answered Sep 26, 2018 in Java by Daisy
• 8,140 points
3,278 views
0 votes
1 answer

Accessing connection from different class in Java / MySQL?

You should just instantiate DoComms with every ...READ MORE

answered Nov 14, 2018 in Database by nirvana
• 3,130 points
1,944 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP