sql查询在插入时失败

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

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

  1. //DB2 CONNECTION FOR ADDING PRODUCTS
  2. var addProducts =
  3. "insert into PRODUCTS ( ITEM, DESCRIPTION, PRICE, SIZES, DIVISION, XS, S, M, L, XL, INTER, EACH_CASE ) VALUES ('" +
  4. req.body.item +
  5. "', '" +
  6. req.body.description +
  7. "', '" +
  8. req.body.price +
  9. "', '" +
  10. allSizes +
  11. "', '" +
  12. req.body.category +
  13. "', '" +
  14. req.body.xs +
  15. "', '" +
  16. req.body.s +
  17. "', '" +
  18. req.body.m +
  19. "', '" +
  20. req.body.l +
  21. "', '" +
  22. req.body.xl +
  23. "', '" +
  24. inter +
  25. "', '" +
  26. each_case +
  27. "' )";
  28. ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
  29. if (err) return console.log(err + "getting error here 1");
  30. conn.query(addProducts, function (err, rows) {
  31. if (err) {
  32. console.log(err + "getting error here 1");
  33. }
  34. var getProductDetails = "select * from products where ITEM = '" + req.body.item + "'";
  35. ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
  36. if (err) return console.log(err + "getting error here 2");
  37. conn.query(getProductDetails, function (err, gianluca) {
  38. if (err) {
  39. console.log(err + "getting error here 2");
  40. }
  41. var productAddedValue = ""
  42. console.log(gianluca)
  43. res.render("add-products2", {
  44. page_title: "add-products2",
  45. data: gianluca,
  46. userName: req.session.username,
  47. FN: req.session.firstname,
  48. LN: req.session.lastname,
  49. CO: req.session.company,
  50. productAddedValue: productAddedValue,
  51. });
  52. conn.close(function () {
  53. console.log("closed the function /add-products p2");
  54. });
  55. });

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

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

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

gudnpqoy

gudnpqoy1#

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

  1. 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#

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

相关问题