com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:“字段列表”错误中的未知列“nombre”?

丹尼尔·姆茨

我不知道为什么这不起作用。我已经在程序的另一部分使用了相同的代码。有什么帮助吗?

 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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档