Skip to Content

Create your First XSJS Webservice in HANA Studio

1. Table TEST1PROD.

/wp-content/uploads/2013/07/image001_250396.png

2. Test data in table.

/wp-content/uploads/2013/07/image003_250403.png

3. Create Product.xsjs file

/wp-content/uploads/2013/07/image005_250409.png

4. Code Snippet in Product.xsjs

  1. function readEntry( rs ) { 
  2.           return
  3.           “PRODUCT_ID” : rs.getString(1), 
  4.           “PRODUCT_NAME” : rs.getString(2), 
  5.           “PRODUCT_DETAIL” : rs.getString(3)}; 
  6.           } 
  7.           $.response.contentType = “text/atom+xml”
  8.  
  9.  
  10.           var conn = $.db.getConnection();   
  11.           var pstmt = conn.prepareStatement( “select * from TEST1PROD where product_detail=?” );  
  12.           pstmt.setString(1, $.request.parameters.get(“id”)); 
  13.           //var pstmt = conn.prepareStatement( “select * from TEST1PROD” );  
  14.           var rs = pstmt.executeQuery();   
  15.           var output=“”
  16.  
  17.  
  18.           var list = []; 
  19.           while(rs.next()) { 
  20.           list.push(readEntry(rs)); } 
  21.           output = JSON.stringify( {“entries”: list } ); 
  22.  
  23.  
  24.          $.response.setBody(output); 
  25.           rs.close(); 
  26.         pstmt.close(); 
  27.         conn.close(); 

URL for test

http://<hanaserver>:8000/MyPackage/Product.xsjs?id=DRINKS

Output Screenshot :

/wp-content/uploads/2013/07/image007_250405.png

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply