I want to update the quantity (+1) in jtable cell upon each click on the product photo (product23 the variable)
private void product23MouseClicked(java.awt.event.MouseEvent evt) {
String pcode = product23.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/salespos","root","");
PreparedStatement pst = con.prepareStatement("select * from product where id = ?");
pst.setString(1, pcode);
ResultSet rs = pst.executeQuery();
if(rs.next() == true)
{
String pname = rs.getString("name");
String price = rs.getString("price");
String quantity = rs.getString("quantity");
name23.setText (pname.trim());
price23.setText("$" +price.trim());
quantity23.setText(quantity.trim());
byte[] image = rs.getBytes("Image");
ImageIcon format = new ImageIcon(image);
product23.setIcon(format);
}
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(pos.class.getName()).log(Level.SE VERE, null, ex);
}
DefaultTableModel model = new DefaultTableModel();
try{
model = (DefaultTableModel)jTable1.getModel();
model.addRow(new Object[]
{
name23.getText(),
price23.getText(),
quantity23.getText(),
});
double sum = 0;
for(int i = 0; i<jTable1.getRowCount(); i++)
{
double x ;
if(jTable1.getValueAt(i, 1).toString().contains("$")){
x = (double) Double.parseDouble(jTable1.getValueAt(i, 1).toString().substring(1));
}
else
x = (double) (Double.parseDouble(jTable1.getValueAt(i, 1).toString()));
sum = (double) (sum + x);
sum = Math.round(sum*100.0)/100.0;
}
txtsub.setText("$"+Double.toString(sum));
}catch(RuntimeException e)
{
}
}