3

I am doing a select query on a DB2 database using NodeJS. The query returns FIRST 5 ROWS.

I want to convert these 5 statement that the query returns into a Json format object. Is there something that is already built that i can reuse to convert query to json ?

var ibmdb = require('ibm_db');

ibmdb.open("DRIVER={DB2};DATABASE=profiledb;HOSTNAME=158.xx.xx.xxx;UID=user;PWD=pass;PORT=1234;PROTOCOL=TCPIP", function (err,conn) {
  if (err) return console.log(err);

  conn.query('SELECT STMT_TEXT, ESTIMATE FROM TABLEUSUAGE WHERE TIMESTAMP > (SELECT CURRENT DATE - 2 DAY FROM SYS.SYSDUMMY1) ORDER BY ESTIMATE DESC FETCH FIRST 5 ROWS ONLY', function (err, data) {
    if (err) console.log(err);

    var data_from_query = data; 

    console.log(data);

    conn.close(function () {
      console.log('done');
    });
  });

});

1 Answer 1

12

Yes try the below statement that would convert your output to Json format.

 console.log(JSON.stringify(data));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.