Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compile fails with ClassNotFoundException

Status
Not open for further replies.

jfriestman

Programmer
Sep 3, 1999
61
US
When I attempt to compile the class below, it returns this error:

C:\...\classes\northwind>javac Employee.java
Employee.java:11: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
Class.forName(DRIVER);
^
1 error

The "Class" class is found in java.lang and the classes.zip file is part of my CLASSPATH so I don't know why it is choking on this line.

Why can't this file find the java classes? Even when I fully qualify the class with java.lang.Class.forName(...) it still chokes.

------------- SOURCE CODE ------------
Code:
package northwind;

import java.lang.*;
import java.sql.*;

public class Employee {

   private String _empId = null;

   public Employee(String empId) {
      this._empId = empId;

      // chokes on this line
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con = null;

      // more code...

      }

   }
 
Never mind, I figured it out... had to wrap Class.forName in a try...catch block. That's all it took.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top