2

There is a problem at runtime with this code which is :

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

but another program of same JDBC driver are run properly but this JDBC driver is found a exception in java applet. So please help me for this problem.

I'm new in Java.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.sql.*;
import java.io.*;

/*<applet code="EmpDetails" width=300 height=500></applet>*/

public class EmpDetails extends Applet implements ActionListener{
TextField firstName, lastName, userId, pass, email, phone;
Button submit,cancel;
String msg = "";

public void init(){

    setLayout(new GridLayout(10,2,0,30));


    Label fname = new Label("First Name : ");
    Label lname = new Label("\nLast Name : ");
    Label uid = new Label("User Id : ");
    Label pas = new Label("Password : ");
    Label emailid = new Label("Email Id : ");
    Label ph = new Label("Phone : ");

    firstName = new TextField(10);
    lastName = new TextField(10);
    userId = new TextField(16);
    pass = new TextField(16);
    email = new TextField(30);
    phone = new TextField(12);
    pass.setEchoChar('*');

    submit = new Button("Submit");
    cancel = new Button("Cancel");

    add(fname);
    add(firstName);

    add(lname);
    add(lastName);
    add(uid);
    add(userId);
    add(pas);
    add(pass);
    add(emailid);
    add(email);
    add(ph);
    add(phone);
    add(submit);
    add(cancel);

    firstName.addActionListener(this);
    lastName.addActionListener(this);
    userId.addActionListener(this);
    pass.addActionListener(this);
    email.addActionListener(this);
    phone.addActionListener(this);
    submit.addActionListener(this);
    cancel.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
        String str = ae.getActionCommand();
        if(str.equals("Submit"))
        {
                try{
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    String url = "jdbc:oracle:thin:@localhost:1521:XE";
                    String id = "system";
                    String passw = "root";

                    Connection con = DriverManager.getConnection(url , id , passw);

                    Statement st = con.createStatement();

                    String u,fn,ln,ps,em,pn;
                    u = userId.getText();
                    fn = firstName.getText();
                    ln = lastName.getText();
                    ps = pass.getText();
                    em = email.getText();
                    pn = phone.getText();
                    String urld = "INSERT INTO EMPDETAILS(id,firstname,lastname,email,password,phone)" + "values" + "('" + u + "','" + fn + "','" + ln + "','" + em + "','" + ps + "','" + pn + "')";
                    st.executeUpdate(urld);
                    con.close();
                    st.close();
                    msg = "Recode added successfull ";
                }

                catch(Exception e){ msg = e.toString();}
        }

        else{
            msg = "No any data added";

        }
        repaint();
    }
    public void paint(Graphics g){
        g.drawString(msg,6,300);


    }
}
1
  • 2
    The exception comes from when you try Class.forName("....OracleDriver") because you don't have the Oracle JDBC classes on your classpath. There are many, many other questions exactly like this, a quick google search will get you an answer. Commented Jul 31, 2016 at 16:50

4 Answers 4

7

The reason why you encounter this Exception is, that you use the wrong package to refer to the OracleDriver class

Therefore, you should change the incorrect class load call

Class.forName("oracle.jdbc.driver.OracleDriver");

into

Class.forName("oracle.jdbc.OracleDriver");

as this class file implements the java.sql.Driver interface which is actually checked for at runtime.

For reference, see also the description in the official JavaDoc provided by Oracle:

The Oracle JDBC driver class that implements the java.sql.Driver interface.

Sign up to request clarification or add additional context in comments.

Comments

3

Solution

  • 1) Firstly download ojdbc6.jar and ojdbc6_g.jar from google.

  • 2) If you are connecting to Oracle 11g from Java and running on version Java 6 then include ojdbc6.jar or ojdbc6_g.jar in your application's classpath.

  • 3) Once you complete the download, paste the files in C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext folder.

1 Comment

How does one do the step you say which is to "include ojdbc6.jar in your application's classpath"? What does that mean?
0

This is just a reference solution for those who has Java 1.8 and oracle Version 12+. In my case i had Java 1.8 therefore downloading oracle8.jar and placing that in the classpath as mentioned above helped to solve my problem.

2 Comments

What do you mean "placing that in the classpath"? We are trying to solve this same error in Python and the meaning of that statement is unclear.
As i mentioned you need to download the oracle8.jar and then paste that jar in "C:\Program Files\Java\jre1.8.0_221\lib\ext" path. This should solve your problem. It solved mine
0

You have to run startNetworkServer within derby Folder (using cmd.exe). Typically, you will get port 1527; then in Eclipse -> Properties -> java path -> classpath you add .jar by browsing to derby/lib/derbyclient.jar; finally within java class with main() method you get

connection = DriverManager.getConnection("jdbc:derby://localhost:1527/nameOfDataBase");

Enjoy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.