Récuperation d'une valeurd'un preparedstatement.
Bonjour la Communauté,
Je cherche a reuperer la valeur de txtMatricule dans cboNatureActionPerformed.
Dois utiliser des parametres?
Merci d'avance
Habiler
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
| private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
conn = ConnectDecisions.ConnectDB();
String strNatureSelected= cboNature.getSelectedItem().toString();
try {
PreparedStatement pst = conn.prepareStatement("insert into Beslissing (Dos_Id, Matricule,Debut,Fin,DateDec,Numero,Nature) values (?,?,?,?,?,?,?)");
pst.setInt(1, Integer.parseInt(txtDos_Id.getText()));
pst.setInt(2, Integer.parseInt(txtMatricule.getText()));
pst.setInt(6, Integer.parseInt(txtNumero.getText()));
pst.setDate(3,convertUtilDateToSqlDate(txtDebut.getDate()));
pst.setDate(4,convertUtilDateToSqlDate(txtFin.getDate()));
pst.setDate(5,convertUtilDateToSqlDate(txtDateDec.getDate()));
pst.setString(7, strNatureSelected);
pst.execute();
//pst.setDate(3, dtDebut);
Date startDate = txtDebut.getDate();
Date endDate = txtFin.getDate();
// In milliseconds
long difference = endDate.getTime() - startDate.getTime();
int diffDays = (int)(difference / 1000 / 60 / 60 / 24);
jLabel5.setText(String.valueOf(diffDays));
// pst.close();
} catch (SQLException ex) {
Logger.getLogger(AddData.class.getName()).log(Level.SEVERE, null, ex);
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| private void cboNatureActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String strNatureSelected= cboNature.getSelectedItem().toString();
if ( "412".equals(strNatureSelected)) {
jPanel2.setVisible(true);
conn = ConnectDecisions.ConnectDB();
Statement requete;
try {
requete = conn.createStatement();
ResultSet rsEnfts= requete.executeQuery("select * from Enfts Where employeenbr = ?");
cboChildName.addItem(rsEnfts.getString("CHILDNAME"));
} catch (SQLException ex) {
Logger.getLogger(AddData.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jPanel2.setVisible(false);
}
} |