Arbaaz Shaikh

Arbaaz Shaikh

  • NA
  • 8
  • 593

I get NullPointerException on adding details.

Dec 25 2018 8:44 AM
private void addActionPerformed(java.awt.event.ActionEvent evt) {
 
String name = name1.getText();
String mmath = math.getText();
String sci = science.getText();
String english = eng.getText();
int tot = Integer.parseInt(mmath)+Integer.parseInt(sci)+Integer.parseInt(english);
double percent1 = tot/3;
String ins = "insert into tbname(name,maths,science,english,total,percent)values('"+name+"','"+mmath+"','"+sci+"','"+english+"','"+tot+"','"+percent1+"')";
try{
Statement st = con.createStatement();
int i=0;
i = st.executeUpdate(ins);
if(i!=0)
{
JOptionPane.showMessageDialog(rootPane, "Data Added :)");
}
else
{
JOptionPane.showMessageDialog(rootPane, "Data Not Added :(");
}
}
catch(Exception ex)
{
System.out.print(ex);
}
}

Answers (2)