Skip to Content
avatar image
Former Member

HANA XS

Hello all, I am new to HANA.

I am currently using hana trial version.

I have created XS application, and it was execeuted successfully, by creating hello.xsjs, xsaccess, xsapp files.

I have created a table called TEST in my inbuilt schema, and also created xsjs file in the following way,

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

function getDataFromTable(){

  var id = $.request.parameters.get("id"); 

  if (id === null) { 

     $.response.setContentType("text/plain"); 

     $.response.addBody("id is null!"); 

  } 

  var val1 = $.request.parameters.get("val1"); 

  if (val1 === null) { 

     $.response.setContentType("text/plain"); 

     $.response.addBody("val1 is null!"); 

  } 

  var output = {}; 

  output.data = []; 

  var conn = $.db.getConnection();

  conn.prepareStatement("SET SCHEMA \"xxxxxxxxx\"").execute(); 

  var st = conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello","TEST\"  values(1,K)");

  st.setString(1,id); 

  st.setString(2,val1); 

  st.executeQuery();

  st.execute(); 

  conn.commit(); 

  var record = []; 

  record.push(id); 

  record.push(val1); 

  output.data.push(record); 

  conn.close(); 

  $.response.setContentType("text/json"); 

  $.response.addBody(JSON.stringify(output)); }

along with this , also created xsaccess, xsprivileges, xsapp,  TEST.hdbtable,model_access.hbd role files .

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

model_access.hbdrole ---------- (role xxxxxxxxxtrial.p1234567.hello::model_access {

     application privilege: xxxxxxxtrial.p1234567.hello::Basic;

}

But when I am trying to run the xsjs file, I am unable to see the table and inserted values , it is showing me blank page.

Could you please help me.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 28, 2015 at 05:46 AM

    Hello Vinni,

    there are several issues in your coding:

    • $.response.setContentType("text/plain"): setContentType is no method of the response object, instead set the property -> $.response.contentType="text/plain"
    • $.response.addBody("id is null!"): addBody is no method of the response object, instead use method setBody -> $.response.setBody("id is null!")
    • conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello","TEST\"  values(1,K)"):
      • not clear here what your table should be here. In case your table name is "TEST" in package "xxxxxxxtrial.p1234567.hello" than use table name "xxxxxxxtrial.p1234567.hello::TEST"
      • also the values "(1, K)" are somehow fixed here, because you are setting the values with the setString method of the statement you have to use placeholder in your statement
      • Statement can look like following: conn.prepareStatement("INSERT INTO \"xxxxxxxtrial.p1234567.hello::TEST\"  values(?,?)");
    • Furthermore: Do you have defined a role which gives you the INSERT privilege on your table?

    Best Regards,

    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Where is the call of function "getDataFromTable" in your Hello.xsjs? Do you set in your new version any response after your insert statement? The line with "st.executeQuery()" can be removed because it is not necessary for the insert.

      Maybe you can set at the end a response body like a string "ok" to check if anything is returned and your script is at least executed.

  • avatar image
    Former Member
    Oct 28, 2015 at 05:14 AM

    hi vinni,

    you can check host file under the folder etc

    Add comment
    10|10000 characters needed characters exceeded