我正在开发SAPUI5应用程序。我需要从db中检索数据,而我使用的是.xsjs,这是我的ajax调用:
jQuery.ajax({
url : "/SimpleProject/services/querytest.xsjs",
method: "GET",
success: function(response) {
console.log(JSON.parse(response));
},
error: function(e) {
sap.ui.commons.MessageBox.alert("ERROR");
}
});
这是我的.xsjs文件,我尝试查询SAP HANA数据库。
try {
$.response.contentType = "application/json";
var conn = $.db.getConnection();
var statement = conn.prepareStatement('SELECT * FROM "_SYS_BIC"."TABLETEST"');
var rs = statement.executeQuery();
conn.commit();
if (rs != undefined)
$.response.setBody(JSON.stringify(rs));
else $.response.setBody(JSON.stringify("empty record set"));
$.response.status = $.net.http.OK;
} catch(e) {
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.setBody(JSON.stringify(e));
} finally {
statement.close();
conn.close();
}
如果我从SQL控制台执行查询,它可以正常工作,但是从xsjs返回的结果总是空的。
答案 0 :(得分:0)
我修复了它,我不能将“rs”对象作为输出发送,但我必须构建另一个对象作为结果;
SELECT a.paygroup, a.EMPLID, a.FILE_NBR, c.name, e.TLM_STATUS, b.rehire_dt
as "Emplmnt_Rltd_Dtes-Rehire Date"
FROM PS_EMPLOYMENT b
inner join SYSADM.PS_JOB a
on a.emplid = b.emplid
inner join SYSADM.PS_PERSONAL_DATA c
on a.emplid = c.emplid
inner join SYSADM.PS_SMS_SUBSCRB_TBL d
on a.paygroup = d.SUBSCRIBER_ID
Inner join PORTAL.PS_TS_EMPL_TLM_STATUS e
on a.emplid = e.emplid
where
b.rehire_dt IS NOT NULL
and d.EFFDT = (select max (d2.effdt) from PS_SMS_SUBSCRB_TBL d2 where
d.SUBSCRIBER_ID = d2.SUBSCRIBER_ID)
and e.EFFDT = (select max (e2.effdt) from PORTAL.PS_TS_EMPL_TLM_STATUS e2
where e.emplid = e2.EMPLID)
and d.EFF_STATUS <> 'T'
order by a.paygroup, a.emplid
现在xsjs工作正常。