cancel
Showing results for 
Search instead for 
Did you mean: 

XS engine project JSON file unreadable code after hana db updated

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What does it look like in the browser when call the xsjs service directly. What data type are your columns? NVARCHAR or VARCHAR? Do you mean to be stringifying the otuput twice?

result = JSON.stringify(res);

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

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

What about any of the SAP delivered apps that use XSJS (like SHINE, XSADMIN, or HALM)? Are they are working fine?

Former Member
0 Kudos

Hi,Thomas .

The data type is nvarchar, and only the Chinese  is unreadable code,other text is OK.

the SAP delivered apps are working fine,

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

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.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I would also point out that now that you are on SPS 09, you can use the new database interface. It avoids the need for type specific get/set functions completely.

Answers (0)