cancel
Showing results for 
Search instead for 
Did you mean: 

UPSERT in XSJS Issues

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

shahid
Product and Topic Expert
Product and Topic Expert
0 Kudos

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)); 

}

Former Member
0 Kudos

Hi Shahid

I tried your solution.I'm facing the same issue.

shahid
Product and Topic Expert
Product and Topic Expert
0 Kudos

Then I guess you dont have privileges to write insert/upsert/delete statements. just check whether select statement works, i believe you will be able to read DB with you logic.

Check with your system admin and ask for privileges.

Former Member
0 Kudos

Hi Shahid

The select statement works fine. I have issues with only insert/upsert/delete statements.

Since i'm using the Trial system i believe it is the issue.

Former Member
0 Kudos

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

Answers (1)

Answers (1)

sreehari_vpillai
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Sreehari

I'm able to execute in console. I'm using a trial system is that an issue?

sreehari_vpillai
Active Contributor
0 Kudos

try pstmt.executeUpdate();

Former Member
0 Kudos

Hi Sreehari

I'm Getting the same error