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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
public class Principale {
static int row1, col1;
public static void main(String[] args) {
row1 = 0;
col1 = 0;
Frame fenetre = new Frame("Cave à vins");
Label label_titre = new Label("Cave à vins", 550, 0, 200, 50);
try {
Object[][] donnees = {{"",""}};
String[] entetes = {"Prénom", "Nom"};
ModeleTableau mm = new ModeleTableau(donnees, entetes);
JTable tableau = new JTable(mm);
JScrollPane scrollPane = new JScrollPane(tableau);
scrollPane.setColumnHeaderView(tableau.getTableHeader());
scrollPane.setBounds(150, 150, 600, 500);
fenetre.add(scrollPane);
fenetre.add(label_titre);
tableau.setBounds(150, 150, 600, 200);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Connexion con = new Connexion();
Statement stat = con.GetConnexion().createStatement();
ResultSet resultat = stat.executeQuery("SELECT * FROM REGION");
while(resultat.next())
{
System.out.print(resultat.getString("ID_REGION"));
System.out.print(" => ");
System.out.println(resultat.getString("NOM_REGION"));
mm.setValueAt(resultat.getString("ID_REGION"), row1, col1);
col1 = col1 + 1;
mm.setValueAt(resultat.getString("NOM_REGION"), row1, col1);
row1 = row1 + 1;
col1 = 0;
//scrollPane.setViewportView(tableau);
}
}
catch (SQLException e){
e.printStackTrace();
}
}
} |
Partager