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.

Note: A SQL connection configuration can only be accessed from a <strong>SAP</strong> <strong>HANA</strong> XS JavaScript application<br />

(.xsjs) file that is in the same package as the SQL connection configuration itself. Neither subpackages<br />

nor sibling packages are allowed to access an SQL connection configuration.<br />

The following example shows the composition and structure of a configuration file AdminConn.xssqlcc for an<br />

<strong>SAP</strong> <strong>HANA</strong> XS SQL connection called AdminConn. On activation of the SQL connection configuration file<br />

AdminConn.xssqlcc (for example, in the package sap.hana.sqlcon), an SQL connection configuration with<br />

the name sap.hana.sqlcon::AdminConn is created, which can be referenced in your JavaScript application.<br />

sap.hana.sqlcon:AdminConn.xssqlcc<br />

{<br />

}<br />

"description" : "Admin SQL connection"<br />

To create a preconfigured SQL connection using the configuration object AdminConn, for example, from inside<br />

your JavaScript application code, you reference the object using the object name and full package path, as<br />

illustrated in the following code example.<br />

Calling the <strong>SAP</strong> <strong>HANA</strong> XS SQL-Connection Configuration File<br />

function test() {<br />

var body;<br />

var conn;<br />

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

try {<br />

conn = $.db.getConnection("sap.hana.sqlcon::AdminConn");<br />

var pStmt = conn.prepareStatement("select CURRENT_USER from<br />

dummy");<br />

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

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

body = rs.getNString(1);<br />

}<br />

rs.close();<br />

pStmt.close();<br />

} catch (e) {<br />

body = "Error: exception caught";<br />

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

}<br />

if (conn) {<br />

conn.close();<br />

}<br />

$.response.setBody( body );<br />

}<br />

test();<br />

To use the SQL connection from your application during runtime, you must bind the SQL connection configuration<br />

to a database user. To maintain this user mapping, <strong>SAP</strong> <strong>HANA</strong> XS provides a dedicated application (the SQL<br />

Connection Configuration Application), which is pre-installed and accessible under the URL http://<br />

:/sap/hana/xs/sqlcc/. You can grant one of the following roles for users who want to use the<br />

SQL Connection Configuration Application to view or maintain the available SQL connection configurations:<br />

● sap.hana.xs.sqlcc::Viewer<br />

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

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

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

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

Saved successfully!

Ooh no, something went wrong!