我不知道为什么这不起作用。我已经在程序的另一部分使用了相同的代码。有什么帮助吗?
try {
PreparedStatement pps;
pps = cn.prepareStatement("INSERT INTO ventas (nombre,precio,cant)
VALUES (?,?,?)");
pps.setString(1, productotxt.getText());
pps.setString(2, preciotxt.getText());
pps.setString(3, cantidadtxt.getText());
pps.executeUpdate();
JOptionPane.showMessageDialog(null, "Registro exitoso!");
} catch (SQLException ex) {
Logger.getLogger(add.class.getName()).log(Level.SEVERE, null, ex);
}
如果有帮助,这是我的 EER 图。
]
使用setInt而不是setString因为值 precio & cantidad在您的数据库中是int类型。
try {
PreparedStatement pps;
pps = cn.prepareStatement("INSERT INTO ventas (nombre,precio,cant)VALUES (?,?,?)");
pps.setString(1, productotxt.getText());
pps.setInt(2, Integer.parseInt(preciotxt.getText()));
pps.setInt(2, Integer.parseInt(cantidadtxt.getText()));
pps.executeUpdate();
JOptionPane.showMessageDialog(null, "Registro exitoso!");
} catch (SQLException ex) {
Logger.getLogger(add.class.getName()).log(Level.SEVERE, null, ex);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句