Création Jtable avec une base de données
Résolu/Fermé
Shakaso
Messages postés
3
Date d'inscription
jeudi 23 avril 2009
Statut
Membre
Dernière intervention
14 mai 2009
-
23 avril 2009 à 16:10
Shakaso Messages postés 3 Date d'inscription jeudi 23 avril 2009 Statut Membre Dernière intervention 14 mai 2009 - 23 avril 2009 à 17:56
Shakaso Messages postés 3 Date d'inscription jeudi 23 avril 2009 Statut Membre Dernière intervention 14 mai 2009 - 23 avril 2009 à 17:56
A voir également:
- Création Jtable avec une base de données
- Fuite données maif - Guide
- Creation compte gmail - Guide
- Base de registre - Guide
- Creation de compte google - Guide
- Creation de site web - Guide
1 réponse
Shakaso
Messages postés
3
Date d'inscription
jeudi 23 avril 2009
Statut
Membre
Dernière intervention
14 mai 2009
23 avril 2009 à 17:56
23 avril 2009 à 17:56
Bon j'ai réussi en passant par une autre méthode.
public static ArrayList Afficheproduitcommande(){
ArrayList <String[]> Res = new ArrayList();
try {
Connection con = Connexion.defaultCon;
Statement sta = con.createStatement();
String Aproduitcommande = "SELECT nom, exploitant, stock FROM PRODUIT WHERE stock<=10";
ResultSet rs = sta.executeQuery(Aproduitcommande);
String[] Stack;
while (rs.next()){
Stack = new String[3];
Stack[0] = rs.getString("nom");
Stack[1] = rs.getString("exploitant");
Stack[2] = rs.getString("stock");
Res.add(Stack);
}
return Res;
} catch (Exception ex) {
throw new Error(ex);
}
}
public class Commande extends JFrame {
public Commande(){
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Pharma & cie");
this.setSize(300, 100);
ArrayList <String[]> al = Connexion.Afficheproduitcommande();
String[][] col = new String[al.size()][3];
for(int i = 0; i < al.size(); i++){
col[i] = al.get(i);
}
String title[] = {"Produit", "Exploitant", "Stock"};
JTable tableau = new JTable(col, title);
this.getContentPane().add(new JScrollPane(tableau));
}
public static void main(String[] args){
Commande fen = new Commande();
fen.setVisible(true);
}
}
public static ArrayList Afficheproduitcommande(){
ArrayList <String[]> Res = new ArrayList();
try {
Connection con = Connexion.defaultCon;
Statement sta = con.createStatement();
String Aproduitcommande = "SELECT nom, exploitant, stock FROM PRODUIT WHERE stock<=10";
ResultSet rs = sta.executeQuery(Aproduitcommande);
String[] Stack;
while (rs.next()){
Stack = new String[3];
Stack[0] = rs.getString("nom");
Stack[1] = rs.getString("exploitant");
Stack[2] = rs.getString("stock");
Res.add(Stack);
}
return Res;
} catch (Exception ex) {
throw new Error(ex);
}
}
public class Commande extends JFrame {
public Commande(){
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Pharma & cie");
this.setSize(300, 100);
ArrayList <String[]> al = Connexion.Afficheproduitcommande();
String[][] col = new String[al.size()][3];
for(int i = 0; i < al.size(); i++){
col[i] = al.get(i);
}
String title[] = {"Produit", "Exploitant", "Stock"};
JTable tableau = new JTable(col, title);
this.getContentPane().add(new JScrollPane(tableau));
}
public static void main(String[] args){
Commande fen = new Commande();
fen.setVisible(true);
}
}