Exception in thread "main" java.lang.NoClassDefFoundError: sqlj/tools/Sqlj
   程序中有异常跑出 NoClassDefFoundError 用TRY{}   捕捉是JAVA程序问题

解决方案 »

  1.   

    绝对不是Java程序问题。程序是书上的,没有任何错误。
    如果用命令帮助sqlj -help也会出现同样的错误。
      

  2.   

    完整的程序如下:
    /**
     * Program Name: TokSequence.java
     */import java.util.*;public class TokSequence {
    private StringTokenizer tk;

    public TokSequence(StringTokenizer tk1) {
    tk = tk1;
    }

    public int getInt() {
    int n = Integer.valueOf(tk.nextToken()).intValue();
    return n;
    }

    public double getDouble() {
    double d = Double.valueOf(tk.nextToken()).doubleValue();
    return d;
    }

    public String getString() {
    return tk.nextToken();
    }
    }/**
     * Program Name: AcctsForProjs.sqlj
     */
    import java.io.*;
    import java.util.*;
    import java.sql.SQLException;
    import oracle.sqlj.runtime.Oracle;#sql iterator DnoAno(int departmentno, int accountno);class AcctsForProjs {
    private BufferedReader input;
    private DonAno aDnoAno;

    public AcctsForProjs() {
    connectDB();
    openInput();
    }

    private void runAcctsForProjs() {
    int accountno, departmentno, projectno;
    String line;

    try {
    while(true) {
    System.out.println("Please enter a project number" + 
       " (enter a -1 to terminate) >>");
    line = input.readLine();

    projectno = getProjectno(line);
    if(projectno == -1) {
    System.out.println ("Bye");
    System.exit(1);
    }

    if(select(projectno) == 0) {
    while(aDnoAno.next()) {
    System.out.println("Account number = " +
    aDnoAno.accountno() + "Department number = " +
    aDnoAno.departmentno() );
    }
    }

    closeIter(aDnoAno);
    }
    } catch(IOException e) {
    System.err.println("Error reading input.\n" + e);
    closeInput();
    System.exit(1);
    } catch(SQLException e) {
    System.err.println("Error getting data from iterator.\n" + e);
    closeInput();
    System.exit(1);
    }
    }

    private void connectDB() {
    try {
    Oracle.connect(getClass(), "connect.properties");
    } catch(SQLException e) {
    System.err.println("Error connecting to database.\n" + e);
    System.exit(1);
    }
    }

    private void openInput() {
    input = new BufferedReader(new InputStreamReader(System.in));
    }

    private int getProjectno(String line) {
    StringTokenizer tk = new StringTokenizer(line);
    TokSequence g = new TokSequence(tk);
    return g.getInt();
    }

    private int select(int projectno) {
    try {
    #sql
    aDnoAno = {SELECT accountno, departmentno FROM ACCOUNT_LIST
    WHERE projectno = :projectno
      };
    return 0;
    } catch(SQLException e) {
    System.err.println("Cannot execute SELECT statement./n" + e);
    return -1;
    }
    }

    private void closeIter(DnoAno aDnoAno) {
    try {
    aDnoAno.close();
    } catch(SQLException e) {
    System.err.println("Cannot close iterator.\n" + e.toString());
    closeInput();
    System.exit(1);
    }
    }

    private void closeInput() {
    try {
    input.close();
    } catch(IOException e) {
    System.err.println("Cannot close buffered stream.\n" + e.toString());
    System.exit(1);
    }
    }

    public static void main(String[] args) {
    AcctsForProjs maincode = new AcctsForProjs();
    maincode.runAcctsForProjs();
    }
    }
      

  3.   

    输入如下命令:
    sqlj AcctsForProjs.sqlj TokSequence.java
    你这命令是在哪儿执行的呀,JAVA东东发布给ORACLE了没呀?猫咪有点糊涂
      

  4.   

    不是提示没有找到类文件吗
    把相应的类文件放到你的class-path下
      

  5.   

    我已经将sqlj目录和jdbc目录下的类文件放入了classpath下了
      

  6.   

    Installation
    Configure your environment as follows: We assume that SQLJ has been installed with the Oracle installer. Let ORACLE_HOME be the location into which your Oracle products have been installed. 
    Verify your JDBC installation before using SQLJ. Refer to the section "Getting Started" in the book SQLJ Developer's Guide and Reference Oracle 9i Release 1 (9.0.1) for information on testing your SQLJ and JDBC installations. (Note: You must be signed up for the Oracle Technology Network at http://technet.oracle.com in order to access the online documentation.) 
    Specifically, in order to use SQLJ you must have ORACLE_HOME/jdbc/lib/classesxxx.zip in your CLASSPATH environment variable (where xxx is either 111 or 12, depending on the version of your Java compiler). Additionally -depending on the nature of your JDBC driver- dynamic link libraries may have to be installed. Ensure that the directory ORACLE_HOME/bin is included in your environment variable PATH. 
    You must add the files ORACLE_HOME/sqlj/lib/translator.zip and one of the ORACLE_HOME/sqlj/lib/runtimexxx.zip libraries. to the environment variable CLASSPATH. 
    If you use JDK 1.1.x and Oracle JDBC 9.0.1 use runtime11.zip. If you use JDK 1.2 or later and Oracle JDBC 9.0.1 use runtime12.zip. You can uso use runtime12ee.zip if you have a J2EE environment.
    If you use an Oracle JDBC driver version prior to JDBC 9.0.1 use runtime.zip. 
    If you do not have an Oracle JDBC driver in your environment use runtime-nonoracle.zip. IMPORTANT! Earlier SQLJ releases only required that you place translator.zip in the CLASSPATH in order to translate and/or run SQLJ programs. 
    SQLJ versions 8.1.7 and later require additionally one of the runtime zip files (runtime.zip, runtime11.zip, or runtime12.zip) in your CLASSPATH in order to translate SQLJ programs. 
    This completes the installation.
      

  7.   

    OK,就这样搞定了,还是CLASSPATH设置问题哦。唉~~~