简体   繁体   中英

Java Program compile and run in command prompt successfully but not in myeclips?

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 ie 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

  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM