Skip to Content
avatar image
Former Member

UPSERT in XSJS Issues

Hi Experts

I'm trying to INSERT/UPSERT values into my tables using the following xsjs code

try{

  var conn = $.db.getConnection(); 

  var query ="UPSERT  \"NEO_EZPCFVLMDTZUPGEXJXXXXX\".\"LinkedIN_Connections\" VALUES('x','x','x','x','x','x','x','x','x')";

  $.response.setBody("Success");

  $.trace.debug(query);

  var pstmt=conn.prepareStatement(query);

  var rs=pstmt.execute();

  $.response.setBody(rs);

   conn.commit(); 

}

but i'm getting the following error(p.s I'm using a trial system)

dberror(Connection.prepareStatement): 258 - insufficient privilege: Not authorized at ptime/query/checker/query_check.cc:2547

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 24, 2014 at 09:12 AM

    try this ...

      var f1 = $.request.parameters.get('f1');

      var f2 = $.request.parameters.get('f2'); 

      var f3 = $.request.parameters.get('yf3'); 

      var output = {}; 

      output.data = []; 

      

      var query =   // YOUR QUERY

         'insert into "SCHEMA"."PATH::TABLE_NAME" values(?,?,?)';

      var conn = $.db.getConnection();

      var cstmt = conn.prepareCall(query);

      cstmt.setString(1,f1);

      cstmt.setString(2,f2);

      cstmt.setString(3,f3);

      cstmt.execute();

     

      conn.commit(); 

     

      conn.close(); 

      

      $.response.contentType = 'text/json';

      $.response.setBody(JSON.stringify(output)); 

    }

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi,

      You clearly do not have privilege to modify the table content. Since it is a trial system, changing the data might not work. If you have an instance where you have your own user id, then ask the admin to give you insert, modify, delete, drop etc privilege on the object.

      Regards,

      Piyush

  • Dec 23, 2014 at 10:27 AM

    Are you able to execute the query from HANA Studio console ? Probably the user name you are using does not have the update/insert privilege on the table .

    Sreehari

    Add comment
    10|10000 characters needed characters exceeded