Initialiser variable JDBC
Bonsoir la Communaute.
Je recherche le contenu d un enregistrement avec comme Matricule MatriculeToFind.
Mais j essaie d initialiser ma variable MatriculeToFind() qui est un TextField.
Mais j echoue au niveau de String idText = MatriculeToFind.getText();
Qui peut m aider?\\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 29 30 31 32 33 34
| private void MatriculeToFindMousePressed(java.awt.event.MouseEvent evt) {
Connection conn = null;
PreparedStatement ps = null;
String idText = MatriculeToFind.getText();
// validate that idText is a positive int here
int id = Integer.parseInt(idText);
String SQL = "SELECT Matricule,Nom,Prenom FROM Signaletique WHERE Matricule = ?";
try {
conn = Connect.ConnectDB();
ps = conn.prepareStatement(SQL);
ResultSet rs =ps.executeQuery(); {
ps.setInt(1, id);
System.out.println(id);
while( rs.next() ) {
MatriculeFinded.setText(rs.getString(1));
NomFinded.setText(rs.getString(2));
PrenomFinded.setText(rs.getString(3));
//Display values
}
}
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
} |