【发布时间】:2025-11-30 09:15:01
【问题描述】:
我有这个简单、标准和简单的 sql 查询,但我无法找出问题所在。看起来还不错,但无法找出问题所在...它给了我一个错误(您可以在下面找到),但首先,这是插入查询。
//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'
}
不知道如何解决这个问题!感谢您的帮助!
【问题讨论】:
-
你能附上你用来向数据库发送命令的查询吗?
-
@JaisonThomas 刚刚更新了问题
-
使用准备好的语句 (conn.prepare) 而不是查询 (conn.query)。使用准备好的语句修复了由于 req.body 值中的单引号引起的错误。
标签: javascript sql node.js db2