Thursday, May 13, 2021

Node js Slip 6b Solution

 

a)     b.  Create a Node.js file that Insert Multiple Records in "student" table, and display the result object on console.        [Marks 25)


//student.js 

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

Slip 10. Write a jQuery code to make first word of each statement to bold.

  Slip 10. Write a jQuery code to make first word of each statement to bold.  <!DOCTYPE html> <html>   <head>     <scri...