amelioration classe connectBd
Je commence en J2EE et je ne comprends prkoi ça ne mache pas
Voila j'ai une classe Connect Bd
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package fr.cassoto.Bdd;
public class ConnectBd {
private String url;
private String login;
private String password;
private String nomDriver;
java.sql.Connection cnx;
java.sql.Statement req;
/** Creates a new instance of ConnectBd */
public ConnectBd() {
url ="jdbc:mysql://localhost:3306/projet";
login="root";
password="java";
nomDriver="org.gjt.mm.mysql.Driver";
cnx = null;
req = null;
}
public java.sql.Statement connect (){
try{
Class.forName(nomDriver);
cnx = java.sql.DriverManager.getConnection(url,login,password);
req = cnx.createStatement();
}catch(java.sql.SQLException e){
System.out.println("SQL Error : Erreur de requete");
e.printStackTrace();
}
catch(ClassNotFoundException e){
System.out.println("Erreur de classe : Erreur de chargement de driver");
e.printStackTrace();
}
return req;
}
public void deconnect(){
try {
req.close();
cnx.close();
}catch(java.sql.SQLException e){
System.out.println("SQL Error : Erreur de requete");
e.printStackTrace();
}
}
} |
et une page JSP listUtilisateur
Code:
1 2 3 4 5 6 7 8
| <%@ page import="fr.cassoto.Bdd.ConnectBd" %>
<%
String requete = "Select Idclient, nom, prenom, droit.droit from client, droit where client.droit=droit.iddroit order by iddroit, nom,prenom";
ConnectBd req = new ConnectBd();
java.sql.Statement re = req.connect();
java.sql.ResultSet rs = re.executeQuery(requete); |