Skip to Main Content

Programming Languages & Frameworks

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

INSERT - Error: NJS-044: named JSON object is not expected in this context

3784542Sep 26 2018 — edited Sep 27 2018

I am trying to perform an insert statement, and am getting the following error: Error: NJS-044: named JSON object is not expected in this context.

I've used the example insert from the  Github (https://github.com/oracle/node-oracledb/blob/master/examples/em_insert1.js ) and changed out parameters to fit my project.

what's causing this?

var doconnect = function(cb) {

  oracledb.getConnection(serviceConfig, cb);

  console.log("oracle connected");

};


var dorelease = function(conn) {

  conn.close(function(err) {

   if (err) console.error(err.message);

  });

};


var doinsert = function(conn, cb) {

  var sql =

   "INSERT INTO WU_SOURCE_RECORDS VALUES (:SOURCE_RECORD_ID, :DWR_SOURCE_ID, :HISTORY_YEAR, :JAN_ACFT, :FEB_ACFT, :MAR_ACFT, :APR_ACFT, :MAY_ACFT, :JUN_ACFT, :JUL_ACFT, :AUG_ACFT, :SEP_ACFT, :OCT_ACFT, :NOV_ACFT, :DEC_ACFT, :ANNUAL_ACFT, :MEASURE_UNITS)";


  var binds = [

  {

  SOURCE_RECORD_ID: 123456,

  DWR_SOURCE_ID: 987456,

  HISTORY_YEAR: 1999,

  JAN_ACFT: 1,

  FEB_ACFT: 4,

  MAR_ACFT: 2,

  APR_ACFT: 6,

  MAY_ACFT: 1,

  JUN_ACFT: 3,

  JUL_ACFT: 4,

  AUG_ACFT: 0,

  SEP_ACFT: 0,

  OCT_ACFT: 3,

  NOV_ACFT: 2,

  DEC_ACFT: 10,

  ANNUAL_ACFT: 143,

  MEASURE_UNITS: "acre feet"

  }

  ];


  var options = {

  autoCommit: true

   /*bindDefs: {

  a: { type: oracledb.NUMBER },

  b: { type: oracledb.STRING, maxSize: 15 }

  }*/

  };


  conn.execute(sql, binds, options, function(err, result) {

   console.log("in execute");

   console.log(sql, binds, options);

   if (err) {

   console.log(err);

   return cb(err, conn);

  } else {

   console.log("Result is:", result);

   return cb(null, conn);

  }

  });

};


async.waterfall([doconnect, doinsert], function(err, conn) {

  if (err) {

   console.error("In waterfall error cb: ==>", err, "<==");

  }

  if (conn) dorelease(conn);

});

Comments

Processing

Post Details

Added on Sep 26 2018
1 comment
7,781 views