互联网站点Java Applet与firebird数据库

时间:2013-11-05 16:40:03

标签: java applet

我有一些项目可以为mys自己做,但我无法解决难题:) 例如,我有这样的代码,但它在我的网站上也没有工作

它抛出: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. 我使用console编译代码并获取.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>
    

1 个答案:

答案 0 :(得分:1)

您应该archive添加applet tag。如果你没有Firebird.jar,你应该创建它。

<applet 
    code="firebird/Firebird" 
    archive="Firebird.jar" 
    width=1000
    height=500>
</applet>