I tried node-jt400 (SQL query)

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.

nodejt02.PNG Execution result nodejt03.png 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);
        }
    )
});

nodejt04.png

Recommended Posts

I tried node-jt400 (SQL query)
I tried node-jt400 (SQL Update)
I tried node-jt400 (SQL stream)
I tried node-jt400 (Programs)
I tried node-jt400 (execute)
I tried node-jt400 (Transactions)
I tried node-jt400 (Environment construction)
I tried node-jt400 (IFS write)
I tried node-jt400 (IFS read)
I tried Spring.
I tried tomcat
I tried youtubeDataApi.
I tried refactoring ①
I tried FizzBuzz.
I tried JHipster 5.1
[I tried] Spring tutorial
I tried running Autoware
I tried using Gson
I tried QUARKUS immediately
I tried using TestNG
I tried Spring Batch
I tried using Galasa
I tried using azure cloud-init
I tried Spring State machine
I tried Drools (Java, InputStream)
I tried Rails beginner [Chapter 1]
I tried using Apache Wicket
I tried the VueJS tutorial!
I tried using Java REPL
I tried source code analysis
I tried the FizzBuzz problem
I tried putting XcodeGen + SwiftPM
I tried Rails beginner [Chapter 2]
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to verify yum-cron
I tried Jets (ruby serverless)
I tried metaprogramming in Java
I tried to implement flexible OR mapping with MyBatis Dynamic SQL
I tried using anakia + Jing now
I tried Angular tutorial + SpringBoot + PostgreSQL
I tried to chew C # (indexer)
I tried using JOOQ with Gradle
[K8s] I tried communication between pods!
I tried morphological analysis with MeCab
I tried a little digdag docker.run_options
I tried to summarize iOS 14 support
I tried to interact with Java
I tried UDP communication with Java
I tried putting Domino11 in CentOS7
I tried the Java framework "Quarkus"
[Rails] I tried deleting the application
I tried using Java8 Stream API
I tried Java's micro-benchmark tool JMH
I tried using JWT in Java
I tried GraphQL with Spring Boot
I tried to summarize Java learning (1)
I tried to understand nil guard
[Android] I tried using Coordinator Layout.
I tried installing CentOS 8 on ESXi 6.7
I tried Flyway with Spring Boot