简体   繁体   English

Java 程序在命令提示符下成功编译并运行,但在 myeclips 中却没有?

[英]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.我正在通过编写这个简单的代码来学习 jdbc 并使用 Oracle 数据库。 The IDE i'm using is MyEclips.我使用的 IDE 是 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:但问题是当我在命令提示符下编译和运行这个程序时它可以正常工作,但是当我尝试在我的 IDE 中编译和运行这个程序时,即 MyEclips 通过一条错误消息:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 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.验证所请求类的名称是否正确,以及类路径中是否存在相应的 .jar 文件。 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.如果指定的 .jar 文件存在于您的类路径中,那么您的应用程序的类路径将被覆盖,您必须找到应用程序使用的确切类路径。
  • 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.如果异常是由第三方类引起的,您必须确定引发异常的类,然后在类路径中添加缺少的 .jar 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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