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
|
private void remplirJPanel() {
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
jpanel.setLayout(new BoxLayout(jpanel3,BoxLayout.Y_AXIS));
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://xxx;DatabaseName=xxx;user=xxx;password=xxx");
statement = conn.createStatement();
String sql = "SELECT distinct champ1 from Table1";
rs = statement.executeQuery(sql);
while(rs.next()){
final JCheckBox jcheckbox = new JCheckBox(rs.getString("champ1"));
jpanel.add(jcheckbox);
jcheckbox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) {
ConstruireRequeteSQL(jcheckbox.isSelected(),jcheckbox.getText());
}});
}
conn.close();
}
catch (Exception e) {
System.out.print("Exception: "+e);
}
} |