Bonjour,
Quand j'essaye d'exécuter une requete telle que select * from Medium, mon programme ne charge que la liste des personnes, la 1ère ligne de la médiathèque puis à partir de la 2ème ligne, il pointe sur null. Et la liste des emprunts , n'est même pas chargée.
Pourtant le tableau est bien créé. Lorsque je le compile , on voit bien le tableau en entier.
Je ne sais pas si c'est un problème dû à mon boucle ou pas. Je ne le pense pas mais qui sait?
Voici mon code :
public void initParBD(IHM ihm){
/* On instancie lesPersonnes */
try{
ResultSet p = lecture.executeQuery("Select * from Personne");
while(p.next()){
String n = p.getString(1);
String pre = p.getString(2);
int nbEmpr = p.getInt(3);
int in = p.getInt(4);
boolean i = false;
if(in != 0)
i = true;
Personne perso = new Personne(n, pre, nbEmpr, i);
ihm.addPers(perso);
}
}
catch(Exception ex){
ihm.affiche("pb instanciation personnes ",ex);
}
/* On instancie la Médiatheque */
try{
ResultSet m = lecture.executeQuery("Select * from Medium");
while(m.next()){
String t = m.getString(1);
String a = m.getString(2);
int tot = m.getInt(3);
int v = m.getInt(4);
int d = m.getInt(5);
double n = m.getDouble(6);
String type = m.getString(7);
if(type.equals("K7")){
int du= m.getInt(8);
me = (Medium)new K7(t,a,tot,du,v,n,d);
}
if(type.equals("DVD")){
String z = m.getString(9);
me = (Medium)new DVD(t,a,tot,z,v,n,d);
}
if(type.equals("CD")){
String f = m.getString(10);
me = (Medium)new CD(t,a,tot,f,v,n,d);
}
//
ihm.affiche(type+t+" "+a+" "+n,null);
ihm.addMed(me);
}
}
catch(Exception ex){
ihm.affiche("pb instanciation medium ",ex);
}
/* On instancie lesEmprunts */
try{
ResultSet e = lecture.executeQuery("Select * from Emprunt");
while(e.next()){
String n = e.getString(1);
String pre = e.getString(2);
Personne p = chercherPers(ihm,n,pre);
String t = e.getString(3);
String a = e.getString(4);
Medium m = chercherMed(ihm,t,a);
Date deb = e.getDate(5);
Date fin = e.getDate(6);
Emprunt em = new Emprunt(m, p, deb, fin);
ihm.addEmpr(em);
}
}
catch(Exception ex){
ihm.affiche("pb instanciation emprunt ",ex);
}
}
/**
* Méthode fermant la connexion avec le BD et le Statement
*/
public void close() throws SQLException{
lecture.close();
connex.close();
}
Configuration: Linux Fedora
Firefox 1.5.0.8