0

我有一些项目要为自己做,但我无法解决难题:) 例如我有这样的代码,但它在我的网站上也不起作用

它抛出:NoClassDefFoundError

  1. 我创建文件 .java 并将其与数据库链接(?)

    package firebird;
    
    import java.sql.*;
    
    public class Firebird {
    
        public static void main(String[] args) throws ClassNotFoundException {
    
        String pathToDatabase;
        String userName;
        String password;
        String sql;
    
        sql = "SELECT * FROM EMPLOYEE";
        password = "masterkey";
        userName = "sysdba";
        pathToDatabase = "C:/Program Files/Firebird/Firebird_2_5/examples/empbuild/EMPLOYEE.FDB";
    
    try {
        Class.forName("org.firebirdsql.jdbc.FBDriver");
        } catch(ClassNotFoundException cnfe) {
          System.out.println(cnfe.toString());  
          System.out.println("org.firebirdsql.jdbc.FBDriver not found"); 
        }
    // Retrieve a connection.
    try {
        Statement stmt = null;
        ResultSet rst = null;
        Connection conn = DriverManager.getConnection(
        "jdbc:firebirdsql:localhost/3050:" + pathToDatabase, userName, password);
    try {
      stmt = conn.createStatement();
      rst = stmt.executeQuery(sql);
      int columnCount = rst.getMetaData().getColumnCount();
      int recordIndex = 0;
     while(rst.next()) {
      recordIndex++;
      System.out.println("Record: " + recordIndex);
        for (int i=1;i<=columnCount;i++) {
         System.out.print(rst.getMetaData().getColumnName(i));
         System.out.print(": ");
         System.out.println(rst.getString(i));
        }
     }
    } finally {
    // close the database resources immediately, rather than waiting
    // for the finalizer to kick in later
      if (rst != null) { rst.close(); }
      if (stmt != null) { stmt.close(); }
      conn.close();
    }
    } catch(SQLException se) {
      System.out.println(se.toString());
    }
    }        
    
    }
    
  2. 我用控制台编译代码并获取 .class 文件

  3. 我使用以下代码创建了一个 .html 文件:

    <HTML>
     <HEAD>
     <TITLE>Java_DB</TITLE>
     </HEAD>
     <BODY>
     Svetainė parašyta su java ir joje duombazė <BR><BR>
    
     <applet code="Firebird.class" width="1000" height ="500">
    
     </BODY>
     </HTML>
    
4

1 回答 1

1

你应该添加archiveapplet tag喜欢的。如果你还没有 Firebird.jar,你应该创建它。

<applet 
    code="firebird/Firebird" 
    archive="Firebird.jar" 
    width=1000
    height=500>
</applet>
于 2013-11-05T16:48:11.683 回答