Issue
try {
String query = "insert into TotalStock (Item Name, Perishable, Stock, Price) values (?,?,?,?)";
PreparedStatement pst = connection.prepareStatement (query);
pst.setString(1, textField.getText());
pst.setString(2, textField_3.getText());
pst.setString(3, textField_2.getText());
pst.setString(4, textField_1.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "Item Saved!") ;
pst.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
Solution
Blanks in column names is a very bad idea. You should rename the column.
For now you can also use backticks to escape the blank:
String query = "insert into TotalStock (`Item Name`, Perishable, Stock, Price) values (?,?,?,?)";
Answered By - Jens
Answer Checked By - David Marino (JavaFixing Volunteer)