var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var oracledb = require('oracledb');
const morgan = require('morgan');
app.use(morgan("combined"));
app.use(bodyParser.json());
app.post("/user", function (req, res){
console.log("Posting data into table :");
const connection = oracledb.getConnection(
{
user : "SYSTEM",
password : "************",
connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DESKTOP-*****)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)))"
})
.then(function(conn) {
return conn.execute(
`INSERT INTO table1 (department_id, department_name) VALUES` [req.body.department_id, req.body.department_name]
)
.then(function(result) {
console.log(result.rows);
res.json(result.rows);
return conn.close();
})
.catch(function(err) {
console.error(err);
return conn.close();
});
})
.catch(function(err) {
console.error(err);
});
connection.release(
function (err) {
if (err) {
console.error(err.message);
} else {
console.log("POST /user_profiles : Connection released");
}
});
});
app.listen(3000, ()=>{
console.log("Connected . . . ")
})
I am unable to release the connection in the POST program written above, the error is shown as follows :
Error: NJS-006: invalid type for parameter 1 at Object.assert (C:\Node\NodePrograms\node_modules\oracledb\lib\util.js:80:11) at Connection.execute (C:\Node\NodePrograms\node_modules\oracledb\lib\connection.js:129:12) at C:\Node\NodePrograms\node_modules\oracledb\lib\util.js:116:16 at new Promise () at Connection.execute (C:\Node\NodePrograms\node_modules\oracledb\lib\util.js:104:14) at C:\Node\NodePrograms\postdb.js:20:23
I am using ARC of chrome to post the data.Its showing 500 Internal Server Error and <pre>TypeError: connection.release is not a function
I am using Node JS and Oracle DB.