线程 "main" java.lang.ClassNotFoundException 中的异常:org.apache.derby.jdbc.ClientDriver

Exception in thread "main" java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver

我的程序在执行时显示这些错误:

Exception in thread "main" java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at Aula4.main(Aula4.java:13)
Picked up _JAVA_OPTIONS: -Xmx512M
C:\Users\mikae\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:53: Java returned: 1

我的档案Aula4


import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mikae
 */
public class Aula4 {
    public static void main (String[] args) throws ClassNotFoundException, SQLException {
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            
            String url = "jdbc:derby://localhost:1527/sistema_academico";
            
            String usuario = "app";
            String senha = "app";
            Connection conexao;
            Scanner ler = new Scanner(System.in);
            int id_aluno;
            double nota;
            String nome;
            int i;
            conexao = DriverManager.getConnection(url, usuario, senha);
            String sql = "INSERT INTO aluno VALUES (?, ?, ?)";
            PreparedStatement stm = conexao.prepareStatement(sql);
            ResultSet rs = stm.executeQuery();
            
            System.out.println("Connected!");
            for (i=0;i<4;i++) { 
                
            System.out.println("Welcome! Type your ID");
            id_aluno = ler.nextInt();
            
            System.out.println("Now, type your name");
            nome = ler.next();

            System.out.println("And finally, type your grade");
            nota = ler.nextDouble();
            
            String SQL_Update = "UPDATE aluno SET nota=? WHERE id_aluno=?";
            stm = conexao.prepareStatement(SQL_Update);
            stm.setLong(1, id_aluno);
            stm.setString(2, nome);
            stm.setBigDecimal(3, new BigDecimal(nota));
            
            int registros = stm.executeUpdate();
            
                        while ( rs.next()) {
                id_aluno = rs.getInt("id_aluno");
                nome= rs.getString("nome");
                nota = rs.getDouble("nota");
            }
            
            stm.close();
            }
            
        } catch (SQLException ex) {
            System.out.println("Connection failed!");
        } 
    }
}

我想连接我的数据库。我已经创建了我的数据库,但仍然显示这些错误,我使用的是 Netbeans IDE 8.2.

您需要将 jdbc 驱动程序添加到您的 java 应用程序。如果你有一个 Maven 项目,你可以通过向你添加以下依赖项来添加它 pom.xml:

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyclient</artifactId>
    <version>10.15.2.0</version>
</dependency>

如果您使用 Netbeans,您可以从 https://repo1.maven.org/maven2/org/apache/derby/derby/10.15.2.0/ and add it to the poject by following the guide at https://www.foxinfotech.in/2019/03/how-to-add-external-jar-file-in-netbeans-project.html 下载驱动程序。