When I use int stdId = 1; i. get no error but when I use int stdId = Integer.parseInt(id.getText()); and input the id in JForm i get exception error java.lang.NumberFormatException: For input string: “”
private void searchStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchStudentActionPerformed
// TODO add your handling code here:
try{
st = conn.createStatement();
int stdId = 1;//Integer.parseInt(id.getText());
rst = st.executeQuery("SELECT * FROM STUDENT WHERE stdId = '" + stdId + "'");
if (rst.next()) {
name.setText(rst.getString("stdName"));
guardianName.setText(rst.getString("stdGuardianName"));
bloodType.setText(rst.getString("stdBlood"));
address.setText(rst.getString("stdAddress"));
course.setText(rst.getString("stdClass"));
phoneNum.setText(String.format("%s", rst.getInt("stdPhone")));
} else{
JOptionPane.showMessageDialog(null, "Record not found.");
}
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
i also tried to use
"SELECT * FROM STUDENT WHERE id = '" + stdId + "'";
and
"SELECT * FROM STUDENT WHERE stdId = '" + 1 + "'");
I still get same exception
1