我在https://bitbucket.org/xerial/sqlite-jdbc/downloads/下载了最新版本的sqlite for java driver(sqlite-jdbc-3.16.1.jar)
当我将它用于我的java-web应用程序时,我有这样的错误:“java.sql.SQLException: No suitable driver found for jdbc: sqlite: tennis.db
”
相同的驱动程序适用于桌面应用程序。
这是我的班级连接:
public class ConnexionDB {
private Connection conx = null;
private final String urlBDD = "jdbc:sqlite:tennis.db";
private String MessageError = "Pas d'erreurs ! ";
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.sqlite.JDBC");
this.conx = DriverManager.getConnection(urlBDD);
} catch (Exception ex) {
this.setMessageErreur("BD_Connexion:ouvrirConnexion:Erreur::: " + ex.getMessage());
ex.printStackTrace();
}
}
public void closeConnexion() {
try {
this.conx.close();
} catch (SQLException ex) {
this.setMessageError("BD_Connexion:closeConnexion: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.setMessageError("BD_Connexion:selectExe:Error::: " + 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 AUTOINCREMENT,\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);
}
}
}
怎么办?