Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 545 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 440 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
INSERT - Error: NJS-044: named JSON object is not expected in this context
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?
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);
});
Answers
-
If you look closely at your binds variable, you'll see you've set it to an array with a single element - an object. That variable should be either an array or an object, but in either case, the values should be scalar values. You probably just need to remove the square brackets so that the variable becomes an object.