错误:调用quit后无法将Query排入队列

时间:2017-02-02 05:11:55

标签: javascript mysql node.js

运行下面的代码时出现错误:调用quit后无法将Query排入队列。我需要将一些数据插入两个表中。 你能帮我修改一下我在node.js中真正新的代码,非常感谢你。

Create Contact Service. 
        router.post('/contactinformationdetails', function (req, res, next) {
try {
    var reqObj = req.body;
    console.log(reqObj);
    req.getConnection(function (err, conn) {
        if (err) {
            console.error('SQL Connection error: ', err);
            return next(err);
        } else {
            var insertSql1 = "INSERT INTO contact_person SET ? ";

            var insertValues1 = {
                "site_name": reqObj.sitNam,
                "first_name": reqObj.firName,
                "last_name": reqObj.lastName,
                "position": reqObj.posId,
                "contact_number": reqObj.conNum,
                "organization": reqObj.orga1,
                "email_add": reqObj.emaAdd1,
            };
            var query = conn.query(insertSql1, insertValues1, function (err, result) {
                if (err) {
                    console.error('SQL error: ', err);
                    return next(err);
                }
                console.log(result);
                var Contact_Id = result.insertId;
                res.json({
                    "Cont_id": Contact_Id
                });


                var insertSql5 = "INSERT INTO address_contactperson SET ? ";

                var insertValues5 = {
                    "address_name": reqObj.addNam,
                    "address_one": reqObj.addOne,
                    "address_two": reqObj.addTwo,
                    "city": reqObj.city,
                    "province": reqObj.prov
                };
                 var query1 = conn.query(insertSql5, insertValues5, function (err, result) {
                    if (err) {
                     console.error('SQL error: ', err);
                     return next(err);
                    }
                    console.log(result);
                 });

            });
        }
    });
} catch (ex) {
    console.error("Internal error:" + ex);
    return next(ex);
}
});

1 个答案:

答案 0 :(得分:0)

你必须尝试使用​​mongodb(MongoDB是一个开源文档数据库和领先的NoSQL数据库)这是最简单有效的方法。

router.all('/todo/create', function (req, res) {
    var taskcreate = req.Collection;
    var task = req.body.task;
    var date = req.body.date;
    var status1 = req.body.status1;
    var userid = req.body.userid;
    var users = req.Collection;
    var record = new taskcreate({
        task: task,
        date: date,
        status1: status1,
        userid: userid
    });
    if (task.length > 0) {
        record.save(function (err, result) {
            if (err) {
                res.json({status: 0, message: err})
            } else {
                res.json({status: 1, userid: userid, task: task, date: date, message: " success"});
            }
        })
    } else {
        res.json({status: 0, msg: "Invalid Fields"});
    }
});