我有一些项目要为自己做,但我无法解决难题:) 例如我有这样的代码,但它在我的网站上也不起作用
它抛出:NoClassDefFoundError
我创建文件 .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()); } } }
我用控制台编译代码并获取 .class 文件
我使用以下代码创建了一个 .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>