a) b. Create a Node.js file that Insert Multiple Records in "student" table, and display the result object on console. [Marks 25)
var mysql=require('mysql');
var cn=mysql.createConnection({
host:"localhost",
user:"root",
password:"",
database:"mydb"
});
cn.connect(function(err){
if(err) throw err;
var records=[
['Nishant',60],
['Akshay',80]
];
console.log("connected!");
var sql="INSERT INTO student(sname,percentage)VALUES?";
cn.query(sql,[records],function(err,result){
if(err)throw err;
console.log(result);
console.log("Number of records inserted: "+result.affectedRows);
});
});
/* Output
C:\Users\NEW\nodex>node student.js
connected!
OkPacket {
fieldCount: 0,
affectedRows: 2,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '&Records: 2 Duplicates: 0 Warnings: 0',
protocol41: true,
changedRows: 0
}
Number of records inserted: 2
No comments:
Post a Comment