gpt4 book ai didi

java.lang.ClassNotFoundException : org. apach.derby.jdbc.ClientDriver 异常

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:52 25 4
gpt4 key购买 nike

我想使用 derby 在 netbeans 中操作我的数据库,但我收到此错误:

java.lang.ClassNotFoundException: org.apach.derby.jdbc.ClientDriver

要添加 derby 库,我已经完成了:

  1. 然后右键单击“库”

  2. 在列表中,我选择了 Java DB Driver

这是我的类 ConnexionDB.java 的代码

public class ConnexionDB {

private Connection conx = null;
private final String urlBDD = "jdbc:derby://localhost:1527/tennis;create=true;user=tennis;password=tennis";

private String MessageError = "No Errors ! ";

public ConnexionDB() {
this.openConnexion();
this.createDataBase();
}

private String getMessageError() {
return MessageError;
}

private void setMessageError(String MessageError) {
this.MessageError = MessageError;
}

private void openConnexion() {
try {
Class.forName("org.apach.derby.jdbc.ClientDriver");
this.conx = DriverManager.getConnection(urlBDD);
} catch (Exception ex) {
this.setMessageError("BD_Connexion:ouvrirConnexion:Erreur::: " + ex.getMessage());
ex.printStackTrace();
}
}

public void closeConnexion() {
try {
this.conx.close();
} catch (SQLException ex) {
this.setMessageErreur("BD_Connexion:fermerConnexion:Erreur::: " + ex.getMessage());
}
}

public Object[][] selectExe(String requete) {
Object[][] data = new Object[1][1];

try {
if (requete.toLowerCase().contains("select")) {
Statement ReqExe = this.conx.createStatement();
ResultSet ReqRes = ReqExe.executeQuery(requete);

int nbreColonne = ReqRes.getMetaData().getColumnCount();
int nbreLigne = this.nombreLigne(requete);

data = new Object[nbreLigne + 1][nbreColonne];

for (int i = 1; i <= nbreColonne; i++) {
data[0][i - 1] = ReqRes.getMetaData().getCatalogName(i);
}

int cmptr = 1;
while (ReqRes.next()) {
for (int i = 1; i <= nbreColonne; i++) {
data[cmptr][i - 1] = ReqRes.getString(i);
}
cmptr++;
}
ReqRes.close();
ReqExe.close();
}
} catch (Exception ex) {
this.setMessageErreur("BD_Connexion:selectExe:Erreur::: " + ex.getMessage());
}

return data;
}

private int nombreLigne(String requete) {
int nbreLigne = 0;

try {
if (requete.toLowerCase().contains("select")) {

Statement ReqExe = this.conx.createStatement();
ResultSet ReqRes = ReqExe.executeQuery(requete);
//
while (ReqRes.next()) {
nbreLigne++;
}
ReqRes.close();
ReqExe.close();
}
} catch (Exception ex) {
this.setMessageErreur("BD_Connexion:nombreLigne:Erreur::: " + ex.getMessage());
}
return nbreLigne;
}

public boolean updateExe(String requete) {
boolean data = false;

try {
if (!requete.toLowerCase().contains("select")) {

Statement ReqExe = this.conx.createStatement();

int reqInfo = ReqExe.executeUpdate(requete);

if (reqInfo > 0) {
data = true;
}
ReqExe.close();
}
} catch (Exception ex) {
this.setMessageErreur("BD_Connexion:updateExe:Erreur::: " + ex.getMessage());
}
return data;
}

private void createDataBase() {
try {
Statement ReqExe = this.conx.createStatement();

String tableAdherent = "CREATE TABLE IF NOT EXISTS ADHERENT\n"
+ "(NUMEROADHERENT INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY\n"
+ "(START WITH 1, INCREMENT BY 1),\n"
+ "NOM VARCHAR(24) NOT NULL,\n"
+ "PRENOM VARCHAR(24) NOT NULL,\n"
+ "ADDRESSE VARCHAR(50),\n"
+ "TELEPHONE VARCHAR(24),\n"
+ "EMAIL VARCHAR(30) NOT NULL UNIQUE,\n"
+ "PASSWORD VARCHAR(35) NOT NULL);";
ReqExe.execute(tableAdherent);

String tableTouroi = "CREATE TABLE IF NOT EXISTS TOURNOI\n"
+ "(CODETOURNOI INTEGER PRIMARY KEY AUTOINCREMENT,\n"
+ "NOM VARCHAR(24) NOT NULL,\n"
+ "DATE VARCHAR(30) NOT NULL,\n"
+ "LIEU VARCHAR(30));";
ReqExe.execute(tableTouroi);

String tableInscription = "CREATE TABLE IF NOT EXISTS INSCRIPTION\n"
+ "(IDINSCRIPTION INTEGER PRIMARY KEY AUTOINCREMENT,\n"
+ "NUMEROADHERENT INTEGER NOT NULL,\n"
+ "CODETOURNOI INTEGER NOT NULL,\n"
+ "DATEINSCRIPTION VARCHAR(30) NOT NULL,\n"
+ "CONSTRAINT fk_numeroAdherent Foreign KEY (NUMEROADHERENT) references ADHERENT(NUMEROADHERENT),\n"
+ "CONSTRAINT fk_codeTournoi Foreign KEY (CODETOURNOI) references TOURNOI(CODETOURNOI));";
ReqExe.execute(tableInscription);

ReqExe.close();

} catch (SQLException ex) {
System.out.println("Echecs : Creation des tables");
Logger.getLogger(ConnexionDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

即使我改变了:

Class.forName("org.apach.derby.jdbc.ClientDriver");

到:

Class.forName("org.apach.derby.jdbc.client");

我总是出错!

最佳答案

您正在加载的类名中有错字。

注意 apache 中的 e:

"org.apache.derby.jdbc.ClientDriver"

关于java.lang.ClassNotFoundException : org. apach.derby.jdbc.ClientDriver 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43718241/

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