Skip to Content

how to delete rows from table using XSJS?

Jul 11, 2017 at 03:24 PM


avatar image
Former Member

I have a table with 2 columns, USER and USER_EMAIL. This contains about 5 rows and I want to delete the rows using XSJS. Here is my attempt.

function cleanup(){

    var connection = $.db.getConnection();
    var query;
    try {
        query  = 'DELETE FROM \"SCHEMA\".\"TABLE\" WHERE \"USER\" = ' + "'" + rowValue + "'"; //here rowValue is a string variable

        var pstmt = connection.prepareStatement(query);
       var result = pstmt.executeUpdate();

     }catch (e) {
         $.response.status = $.net.http.INTERNAL_SERVER_ERROR;


I tested the query on HANA and it seems to work but when I run it through XSJS it doesn't work.

This is the query I ran on HANA


I ran both

var result = pstmt.executeUpdate(); and
var result = pstmt.executeQuery();

but neither one works, they run but the table is not updated. executeUpdate() returns "1". Not sure what that means. Also I'm using XS classic. If anyone has some idea of to get this working, please share.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Jul 11, 2017 at 07:35 PM

That method executeUpdate returns 1 means, that your statement updated 1 data record (please the the XS JS API reference for that).

But I assume that the changed data is not commited, cause you have not executed method commit of the connection object (connection.commit()) and the autocommit mode is not enabled.


Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Yeah, I was simply missing that one line of code/