query="INSERT INTO paint_inventory(ID,Name,type,gallons,quarters) VALUES(?,?,?,?,?)";
con.prepareStatement(query);
pstm.setInt(1,Integer.parseInt(itemID_newitem_field.getText()));
pstm.setString(2,name_newitem_field.getText());
pstm.setString(3,type_newitem_field.getText());
pstm.setInt(4,Integer.parseInt(gallons_quantity_newitem_field.getText()));
pstm.setInt(5,Integer.parseInt(quarters_quantity_newitem_field.getText()));
pstm.execute();
JOptionPane.showMessageDialog(rootPane,"item has been registered");
答案 0 :(得分:0)
pstm
吗?希望您需要将prepareStatement
分配给pstm
,然后您可以设置参数值。
同时确保pstm
不会在同一方法或其他方法中用于其他prepareStatement
。每个prepareStatement
都应该有单独的变量名来设置参数值。
query="INSERT INTO paint_inventory(ID,Name,type,gallons,quarters) VALUES(?,?,?,?,?)";
pstm = con.prepareStatement(query); -- assign to pstm then set values
...
...