[英]Heroku error in logs: 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\8.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>
If you use Netbeans you can download the driver from 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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.