I have created a Jtabel tab_an
and I've populated it from my data base with this code:
private void miseajour_congan(){
try{
String sql1 ="select c.matricule,c.nom,e.prénom,c.cong_ID,c.nature,c.statut_dem,c.date_d,c.date_f,c.solde_an,c.report_an,c.durée from congé c where c.nature = 'annuel'";
ps1=conn.prepareStatement(sql1);
rs1=ps1.executeQuery();
tab_an.setModel(DbUtils.resultSetToTableModel(rs1));
}catch(Exception st){
JOptionPane.showMessageDialog(null, st);
}
}
I've also created a Jpanel with some of swing components (checkbox,combobox,textfield,Jdatechooser,Jspinner) and I've added the Jtable to the Jpanel. The problem is that when I click on a row on the Jtable I want all the information contained in the table to be displayed. To do this, I'm using this code but when I click nothing happens and nothing is displayed:
private void tab_anMouseClicked(java.awt.event.MouseEvent evt) {
try {
int ligne =tab_an.getSelectedRow();
String Tab_clic=(tab_an.getModel().getValueAt(ligne,0).toString());
String sql = "SELECT c.matricule,c.nom,c.prénom,c.cong_ID,c.nature,c.statut_dem,c.date_d,c.date_f,c.solde_an,c.report_an,c.durée "
+ "from congé c where c.cong_ID='"+Tab_clic+"' ";
rs=ps.executeQuery(sql);
while(rs.next())
{
String n = rs.getString("nom");
String p = rs.getString("prénom");
StringBuilder st = new StringBuilder();
st.append(n).append(" ").append(p);
String l = st.toString();
empcombo.setSelectedItem(l);
IDtxt1.setText(rs.getString("cong_ID"));
matric_txt.setText(rs.getString("matricule"));
((JTextField)datede_chooz.getDateEditor().getUiComponent()).setText(rs.getString("date_d"));
((JTextField)datefinann_chooz.getDateEditor().getUiComponent()).setText(rs.getString("date_f"));
soldan_spin.setValue(rs.getInt("solde_an"));
reportan_spin.setValue(rs.getInt("report_an"));
String r =rs.getString("durée");
String [] t = r.split(" ");
int num = 0;
if (t.length>=2)
{num = Integer.parseInt(t[0]);
duran_spin.setValue(num);
joursemaine_combo.setSelectedItem(t[1]);}
String x = rs.getString("statut_dem");
if ( x.equals("approuvé"))
{
approve_check.setSelected(true);
}
else if (x.equals("rejeté"))
{
reject_check.setSelected(true);
}
else if (x.equals("en attente") )
{
attente_check.setSelected(true);
}
}}catch(Exception ej)
{ JOptionPane.showMessageDialog(null, ej);
ej.printStackTrace();}
}
This is The DESC of the table congé
nom varchar(255) YES NULL
prénom varchar(255) YES NULL
statut_dem varchar(100) YES NULL
cong_ID int(11) NO PRI NULL auto_increment
matricule int(11) NO MUL NULL
nature enum('annuel','compensateur','maladie','exceptionel') YES NULL
solde_an float YES NULL
report_an float YES NULL
solde_comp float YES NULL
report_comp float YES NULL
solde_mal int(11) YES NULL
solde_excep int(11) YES NULL
cause_excep enum('mariage','décés') YES NULL
date_d varchar(100) YES NULL
date_f varchar(100) YES NULL
durée varchar(50) YES NULL
{
or before}
are also typically redundant. – Andrew Thompson