I am currently working with an attendance management system, but when I click the "save" button this problem shows up 'java.lang.NumberFormatException:For input string:""' Here is my code:
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendance","root","sydneydel");
String sql = "insert into attendance.student_info values(?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1,Integer.parseInt(jTextField2.getText()));
pst.setString(2, last.getText());
pst.setString(3,first.getText());
pst.setString(4,mid.getText());
String gender;
if (jRadioButton1.isSelected()){
gender=jRadioButton1.getText();
}
else{
gender=jRadioButton2.getText();
}
pst.setString(5, gender);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "SUCCESSFUL");
conn.close();
String data1= last.getText();
String data2= first.getText();
String data3= mid.getText();
String data4= gender;
Object[] row = {1, data2 + " " + data3 + " " + data1, data4};
model = (DefaultTableModel) table.getModel();
model.addRow (row);
first.setText("");
jTextField2.setText("");
last.setText("");
mid.setText("");
buttonGroup1.clearSelection();
if((last == null)&& (first==null)&& (buttonGroup1.equals(null))){
JOptionPane.showMessageDialog(null, "SAVE ERROR\nFill-up the information needed");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
}
How can I resolve my problem and how could I improve this program?