Slip 5 - B) Create a Node,js file that Select all records from the "customers" table, and delete the specified record.

 Solution:


insert_record.js

 var mysql = require('mysql');

var con = mysql.createConnection({

  host: "localhost",

  user: "root",

  password: "root",

  database: "studentdb"

});


con.connect(function(err) {

  if (err) throw err;

  console.log("Connected!");

  var sql = "INSERT INTO student (rollno,name, percentage) VALUES ?";  

var values = [  

[1,'abc', 77.6],  

[2,'def', 89.6],  

[3,'ghi', 91.6]  

];  

con.query(sql, [values], function (err, result) 

 {

    if (err) throw err;

    console.log("Number of records inserted: " + result.affectedRows);  

  });

con.query("SELECT * FROM student", function (err, result, fields) {

    if (err) throw err;

    console.log(result);

  });

});


Initiate :

C:\Users\Your Name>node insert_record.js

Post a Comment

0 Comments