private void Approve_btnActionPerformed(java.awt.event.ActionEvent evt) {
int bonus = Integer.parseInt(bonus_txt.getText());
int sal = Integer.parseInt(salary_txt.getText());
int sales = Integer.parseInt(sales_txt.getText());
int net_sal= (bonus*sales)+sal;
String netsal = Integer.toString(net_sal);
String approve = "yes";
here's my update statement
try {
DBconn();
ps = con.prepareStatement("update bonus_table set approved='"+approve+"',net_sal='"+netsal+"' where e_code='"+ecode_txt.toString()+"'and bcode='"+bcode+"'");
ps.executeUpdate();
tableData();
This tableData() function is meant to update the Jtable so it shows recent data, it's not part of the problem so I chose to ommit it from the question. Also, stackoverflow requires me to write a description of my problem even if it's not that hard to describe the problem
} catch (SQLException ex) {
Logger.getLogger(ManagerApproval.class.getName()).log(Level.SEVERE, null, ex);
}
}
my Database connection method
public void DBconn(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bms_db","root","");
ps = con.prepareStatement("select * from bonus_table");
System.out.println(con);
}
catch(ClassNotFoundException ex){
Logger.getLogger(BMS.class.getName()).log(Level.SEVERE,null,ex);
}
catch(SQLException ex){
Logger.getLogger(BMS.class.getName()).log(Level.SEVERE,null,ex);
}
}
these are variables declared within the class, I just included them so the DBconn function doesn't raise any questions.
Connection con;
ResultSet rs;
PreparedStatement ps;
I don't understand it, someone please help the project is due midnight
You might want to try something like:
int result = 0;
result = ps.executeUpdate();
This will give you the number of rows that got updated. If result remains "0" it might be related to some issue with your update statement, like the conditions not matching any record.