28.01.2013 Views

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Request-Processing API Example<br />

The following example shows how to use the request-processing API to display the message “Hello World” in a<br />

browser.<br />

$.response.contentType = "text/plain";<br />

$.response.setBody( "Hello, World !");<br />

Database API Example<br />

The following example shows how to use the database API to prepare and execute an SQL statement. The<br />

response to the SQL query is then prepared and displayed in a Web browser.<br />

var conn = $.db.getConnection();<br />

var pstmt = conn.prepareStatement( "select * from DUMMY" );<br />

var rs = pstmt.executeQuery();<br />

$.response.contentType = "text/plain";<br />

if (!rs.next()) {<br />

$.response.setBody( "Failed to retreive data" );<br />

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;<br />

} else {<br />

$.response.setBody("Response: " + rs.getString(1));<br />

}<br />

rs.close();<br />

pstmt.close();<br />

conn.close();<br />

Related Links<br />

<strong>SAP</strong> <strong>HANA</strong> XS JavaScript Reference<br />

9.5 The SQL Connection Configuration File<br />

In <strong>SAP</strong> <strong>HANA</strong> Extended Application Services (<strong>SAP</strong> <strong>HANA</strong> XS), you use the SQL-connection configuration file to<br />

enable the execution of SQL statements from inside your server-side JavaScript application with credentials that<br />

are different to the credentials of the requesting user.<br />

In cases where it is necessary to execute SQL statements from inside your JavaScript application with credentials<br />

that are different to the credentials of the requesting user, <strong>SAP</strong> <strong>HANA</strong> XS enables you to define the configuration<br />

for individual SQL connections. Each connection configuration has a unique name, for example, Registration or<br />

AdminConn, which is generated from the name of the corresponding connection-configuration file<br />

(Registration.xssqlcc or AdminConn.xssqlcc) on activation in the repository. The administrator can<br />

assign specific, individual database users to this configuration, and you can use the configuration name to<br />

reference the unique SQL connection configuration from inside your JavaScript application code.<br />

If you want to create an SQL connection configuration, you must create the configuration as a flat file and save the<br />

file with the suffix .xssqlcc, for example, MYSQLconnection.xssqlcc. The new configuration file must be<br />

located in the same package as the application that references it. You can activate repository files at any point in<br />

time.<br />

222<br />

P U B L I C<br />

© 2012 <strong>SAP</strong> AG. All rights reserved.<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Writing Server-Side JavaScript Applications

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!