Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

XS engine project JSON file unreadable code after hana db updated

Hi experts!

  we updated our HANA DB from sps 85 to sps 97,unlucky we found all html'text is unreadable code.xsjs file is following:

if ($.request.method === $.net.http.GET) {

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

var result = {};

var sql = "select distinct store_nm from HX_YXT.TB_STORE_INFO where store = ?";

var conn = $.db.getConnection();

var pstmt = conn.prepareStatement(sql);

pstmt.setString(1, store_id);

var rs = pstmt.executeQuery();

     var res = {};

if (rs.next()) {

res.store_name = rs.getString(1);

    }

rs.close();

pstmt.close();

conn.close();

result = JSON.stringify(res);

$.response.contentType = "application/json; charset=UTF-8";

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

}

else {

     $.response.status = $.net.http.INTERNAL_SERVER_ERROR;

}

and i did a test using ODATA,it's right and we also get right text by db sql

.i don't konw why.

what can i do?

thank you very much!

Tags:
replied

In your example you are using getString for an NVARCHAR field. That is incorrect. You should be using getNString. Using getString will cause the exact kind of corruption you are seeing because it treats the data as non-Unicode.

JSDoc: Class: ResultSet

getNString(columnIndex) → {string}

returns a string value of the specified column. getNString is used for NCHAR, NVARCHAR,

SHORTTEXT column types.

getString(columnIndex) → {string}

Returns a string value of the specified column. getString is used for CHAR and VARCHAR column types. ASCII only, not suitable for strings containing Unicode characters.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question