gpt4 book ai didi

java - 带有 firebird 数据库的互联网站点 Java Applet

转载 作者:行者123 更新时间:2023-12-01 13:53:21 26 4
gpt4 key购买 nike

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

它抛出: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>

最佳答案

您应该像这样将archive 添加到您的applet 标记。如果您还没有 Firebird.jar,您应该创建它。

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

关于java - 带有 firebird 数据库的互联网站点 Java Applet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19794130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com