A coding example of node-jt400 is written here, so let's test it accordingly. SQL query
SQLquery.js
var jt400 = require("node-jt400");
var express = require("express");
var app = express();
var pool = jt400.pool({ host: '192.168.X.XXX', user: 'MYUSER', password: 'MYPASS' });
var server = app.listen(8888, function () {
console.log("curl http://localhost:" + server.address().port + '/~');
});
app.get("/query", function (req, res, next) {
let stmt = "select * from member";
let members = [];
pool.query(stmt).then(
function (result) {
var id, lname, fname, prof, tokuten;
for (var i = 0; i < result.length; i++) {
id = result[i].ID;
lname = result[i].LNAME;
fname = result[i].FNAME;
prof = result[i].PROF;
tokuten = result[i].TOKUTEN;
members.push(id + lname + fname + prof + tokuten);
}
res.send(members);
}
)
});
This is an example of simply getting all records without parameters. The result is confirmed by command prompt + curl command. Since it is encoded in utf-8, CHCP 65001 is executed in advance.
Execution result If you don't specify a library, you won't get an error because MYLIB is in the library list. To specify it explicitly, use / (slash).
This is an example of returning in JSON format.
SQLquery.js
app.get("/queryJson", function (req, res, next) {
let stmt = "select * from mylib/member where id <= ? or prof like ?";
pool.query(stmt,[101,'%Ai%']).then(
function (result) {
res.json(result);
}
)
});
Recommended Posts