Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

How to run sql statement in xsjs and get the result as json?

$
0
0

Hi,

 

I am trying to run sql statement in xsjs and get the result as json.

 

Sql Statement on SQL console

SELECT SUM("Column")  AS sum FROM "Table";

This is returning sum= 10000;

 

Now My XSJS file

 

var query = "SELECT SUM(\"Schema_Name\".\"Table_Name\".\"Column_Name\") AS sum FROM \"Schema_Name\".\"Table_Name\"";
var conn = $.db.getConnection();
//var pcall = conn.prepareCall(query);
var pcall = conn.prepareStatement(query);
pcall.execute();
var rs = pcall.getResultSet();
var output = {};
//Here you parse rs and put it to output
while (rs.next()) {  output.total = rs.getString(1);  output.results.push(output);
}
rs.close();
pcall.close();
conn.commit();
conn.close();
$.response.contentType = "application/json; charset=UTF-8";
$.response.setBody(JSON.stringify(output));
$.response.status = $.net.http.OK;

Still not getting it. its giving a blank JSON file.


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>