'Handling Multiple SQL entries in NodeJs
I have a code where I am handling multiple SQL entries. Following is a snippet:
mysqlConnection.query(
"INSERT INTO STUDENT_DESEASE(JEE_ROLL_NO,CHRONIC_DISEASE,DETAILS) VALUES(?,?,?)",
[req.body.jeeroll, req.body.disease, req.body.diseasedetails],
function (err, result, fields) {
if (err) throw err;
console.log("1 row inserted in Student Desease");
}
);
mysqlConnection.query(
"INSERT INTO DD_DB(DD_NO,DD_DATE,DD_AMOUNT) VALUES(?,?,?)",
[req.body.jdd, req.body.jdate, req.body.jamount],
function (err, result, fields) {
if (err) throw err;
console.log("1 row inserted in DD Database");
}
);
mysqlConnection.query(
"INSERT INTO DD_DB(DD_NO,DD_DATE,DD_AMOUNT) VALUES(?,?,?)",
[req.body.idd, req.body.idate, req.body.iamount],
function (err, result, fields) {
if (err) throw err;
console.log("1 row inserted in DD Database");
}
);
Now for supposing my 3rd insertion entry raises an error due to any possible reasons like not valid format or already existing value and all. Before the error, the previous 2 insertion codes have already successfully run. They have inserted their values.
So how do Handle this kind of situation?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
