sql查询在插入时失败

hpcdzsge  于 2021-09-23  发布在  Java
关注(0)|答案(2)|浏览(630)

我有一个简单、标准和简单的sql查询,我无法解决这个问题。看起来没问题,但无法解决问题。。。它给了我一个错误(您可以在下面找到),但首先,这里是insert查询。

//DB2 CONNECTION FOR ADDING PRODUCTS
var addProducts =
  "insert into PRODUCTS ( ITEM, DESCRIPTION, PRICE, SIZES, DIVISION, XS, S, M, L, XL, INTER, EACH_CASE ) VALUES ('" +
  req.body.item +
  "', '" +
  req.body.description +
  "', '" +
  req.body.price +
  "', '" +
  allSizes +
  "', '" +
  req.body.category +
  "', '" +
  req.body.xs +
  "', '" +
  req.body.s +
  "', '" +
  req.body.m +
  "', '" +
  req.body.l +
  "', '" +
  req.body.xl +
  "', '" +
  inter +
  "', '" +
  each_case +
  "' )";

    ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
      if (err) return console.log(err + "getting error here 1");
      conn.query(addProducts, function (err, rows) {
        if (err) {
          console.log(err + "getting error here 1");
        }

        var getProductDetails = "select * from products where ITEM = '" + req.body.item + "'";
        ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
          if (err) return console.log(err + "getting error here 2");
          conn.query(getProductDetails, function (err, gianluca) {
            if (err) {
              console.log(err + "getting error here 2");
            }

            var productAddedValue = ""
            console.log(gianluca)
            res.render("add-products2", {
              page_title: "add-products2",
              data: gianluca,
              userName: req.session.username,
              FN: req.session.firstname,
              LN: req.session.lastname,
              CO: req.session.company,
              productAddedValue: productAddedValue,
            });

            conn.close(function () {
              console.log("closed the function /add-products p2");
            });
          });

}); 它给了我这个错误:

[Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0010N  The string constant beginning with "' )" does not have an ending string delimiter.  SQLSTATE=42603
] {
  error: '[node-ibm_db] SQL_ERROR',
  sqlcode: -10,
  state: '42603'
}

不知道该如何解决这个问题!谢谢你的帮助!

gudnpqoy

gudnpqoy1#

假设您使用的是nodejses5,这应该可以工作,而且更干净

const addProducts =  `insert into PRODUCTS (ITEM, DESCRIPTION, PRICE, SIZES, DIVISION, XS, S, M, L, XL, INTER, EACH_CASE) VALUES ('${req.body.item}', '${req.body.description}', '${req.body.price}', '${allSizes}', '${req.body.category}', '${req.body.xs}', '${req.body.s}', '${req.body.m}', '${req.body.l}', '${req.body.xl}', '${inter}', '${each_case}');`;
eoigrqb6

eoigrqb62#

事实证明,这是一个愚蠢的错误。当我将数据插入数据库时,我添加了一个 ' 在“描述”栏中,这是对整个事件的描述。谢谢大家的帮助

相关问题