I am trying to insert from textfields data into my database. Insert data to a table compte_utilisateur
and I've 2 comboboxes : first for groupe containing names of all groups (alias libelle_groupe
) in my database, and second for statut containing all status values (alias valeur
) in my database.
I want to insert into my db a user ( alias compte_utilisateur
) and to do that i need id_groupe
of the name of group selected in the combobox and id_statut
of the status selected in my combobox.
I've tried this, but i'm having an exception : java.lang.NullPointerException
the code :
ResultSet valeur1= stmtListeLivre.executeQuery("select id_groupe from groupe where libelle_groupe='"+combo_name.getSelectedItem().toString()+"'");
ResultSet valeur2= stmtListeLivre1.executeQuery("select id_statut from statut where valeur='"+jComboBox1.getSelectedItem().toString()+"'");
Number val1 = ((Number) valeur1.getObject(1)).intValue();
Number val2 = ((Number) valeur2.getObject(1)).intValue();
String requete="INSERT INTO compte_utilisateur(Id_compte, Nom, Prenom, Matricule, Id_groupe, Id_statut) VALUES (?,?,?,?,?,?)";
pst=maConnexion.ObtenirConnexion().prepareStatement(requete);
pst.setString(1, jTIdf.getText());
pst.setString(2, jTNom.getText());
pst.setString(3, jTPrenom.getText());
pst.setString(4, jTMatricule.getText());
pst.setString(5, val1.toString());
pst.setString(6, val2.toString());
pst.execute();