1

I'm learning jdbc and working with Oracle database by writing this simple code. The IDE i'm using is MyEclips. But the problem is when I compile and run this program in command prompt it works properly but when I try to compile and run this program in my IDE i.e. MyEclips it through an error message:

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

import java.sql.*;  
class OracleCon{  
public static void main(String args[])
{  
        try
        {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con = null;

        String URL = "jdbc:oracle:thin:@localhost:1521:xe";
        String UN = "HR";
        String PASS = "12345";

        con = DriverManager.getConnection(URL,UN,PASS);

        Statement stmt = con.createStatement();

        String sql = "SELECT * FROM EMPLOYEES";

        ResultSet rs = stmt.executeQuery(sql);

        while (rs.next())
        {
        System.out.println(rs.getString(1)+"   "+rs.getString(2)+"   "+rs.getString(3));
        }

        }

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

I also set the class path in Environment variable.Environment variable snippet

1
  • Please don't add images for anything that can simply be text. Commented Sep 22, 2016 at 7:18

1 Answer 1

1
  • Verify that the name of the requested class is correct and that the appropriate .jar file exists in your classpath. If not, you must explicitly add it to your application’s classpath.
  • In case the specified .jar file exists in your classpath then, your application’s classpath is getting overriden and you must find the exact classpath used by your application.
  • In case the exception is caused by a third party class, you must identify the class that throws the exception and then, add the missing .jar files in your classpath.
Sign up to request clarification or add additional context in comments.

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.