remplir Jtable sous NetBeans
Bonjour, j'ai créé une JFrame sous NetBeans, puis une Jtable avec la "palette design". Le problème est que je n'arrive pas à remplir cette Jtable avec une bdd.
D'habitude, je fais :
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| public class jTable extends JFrame
{
public static Connection conn ;
public static Statement stmt ;
public static ResultSet rs ;
public static String driver = "org.gjt.mm.mysql.Driver" ;
public static String url = new String("jdbc:mysql://localhost/Calendrier") ;
private JTable jt;
public static Vector<Vector> vListe = new Vector<Vector>();
private int ligne;
public static Vector<String> nomChamps;
private JScrollPane scrTextes;
private Container c;
public JfrCalendrier jfrCalendrier = null ;
public jTable()
{
c = getContentPane();
c.setLayout(null);
scrTextes = new JScrollPane();
scrTextes.setBounds(10, 10, 300, 300);
c.add(scrTextes);
setTitle("JTable");
setSize(490, 400);
show();
try
{
//Connexion à la BDD//
Class.forName(driver);
conn = DriverManager.getConnection(url, "root", "sam220889");
stmt = conn.createStatement();
//Requète SQL//
rs = stmt.executeQuery("select Activite from janvier where Jour=1");
//Tant qu'il y a quelque chose dans la table//
while(rs.next())
{
ligne = 0;
Vector<String> vData = new Vector<String>();
for (int col = 1 ; col<=1 ; col++)
{
String s = rs.getString(col);
vData.addElement(s);
System.out.print(s + " " + ligne+ " " + col);
}
System.out.println("");
vListe.addElement(vData);
ligne++;
}
rs.close();
stmt.close();
conn.close();
nomChamps = new Vector<String>();
nomChamps.add("Activite");
jt = new JTable(vListe,nomChamps);
jt.setBounds(10, 10, 300, 300);
scrTextes.setViewportView(jt);
repaint();
}
catch(SQLException exce)
{
System.out.println("SQLException : " + exce.getMessage());
}
catch (ClassNotFoundException exce)
{
exce.printStackTrace();
}
}
public static void main(String agrs[])
{
jTable fenetre = new jTable() ;
fenetre.setVisible(true) ;
}
} |
Mais, là, vu que j'ai tout fait avec la palette, je suis un peu perdu, je ne sais pas où ni comment placer ce code.
Help me svp.