Quantcast
Channel: SCN : Blog List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 676

Displaying data on browser using server side Javascript (.XSJS) file

$
0
0

Target Audience: Beginner

 

Why I'm posting this simple example?

============================

I'm from different programming background, just started to catch up with HANA development. I was following examples from official hana_dev_en.pdf (google it to download).

 

Actually logic of code piece given on page 78 is similar to the one I extracted from SAP documentation.

 

I could understand that Newbies usually fed up when they couldn't get the output when they follow the examples from book.

 

 

Prerequisite

=========

1. should should have added new system(database), setup new work space and created project if not follow this simplified guidance (http://www.saphana.com/docs/DOC-3017)

 

 

2. Follow the tutorial from hana_dev_en.pdf , you should have other files already in your project (.xsaccess , .xsapp)

 

Note: don't confuse yourself about DUMMY table. it is actually a public synonym accessible for all users regardless of whatever  SCHEMA you are currently using

 

 

Lets start

 

clear  content of your  MyFirstSourceFile.xsjs file and paste the following code (clearly documented for better understanding)

 

// execute query
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement( "select * from DUMMY" );
var rs = pstmt.executeQuery();


// writing result set to response body
$.response.contentType = "text/plain";
if (!rs.next()) {
    $.response.setBody( "Failed to retreive data" );    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
} else {    $.response.setBody("Response: " + rs.getString(1));
}


// cleanup
rs.close();
pstmt.close();
conn.close();

 

Commit your file

Activate it

 

and Run it on your browser


Viewing all articles
Browse latest Browse all 676

Trending Articles



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