我正在学习jdbc并通过编写这个简单的代码来使用Oracle数据库。我正在使用的IDE是MyEclips。但问题是,当我在命令提示符下编译并运行此程序时,它正常工作,但是当我尝试在我的IDE中编译并运行此程序时,即通过错误消息MyEclips:
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);
}
}
}
我还在环境变量中设置了类路径。Environment variable snippet
答案 0 :(得分:1)