Skip to Content

how to execute sql statement remotely on SAP HANA database instance

May 19, 2017 at 10:16 AM


avatar image
Former Member


I am trying to execute sql statement on SAP HANA database instance using the following bash script:

#!/bin/bash -ex PATH=$PATH:~/sap/neo/tools:~/sap/hdbclient # add console client and HANA client to PATH # TODO replace with your user ID account=mysubaccount # TODO replace with your subaccount ID dbSchema=myschema # TODO replace with your schema

json=$( open-db-tunnel -h -a "$subaccount" -u "$user" -p "$HCP_PASSWORD" -i "$dbSchema" --background --output json) regex='.*"host":"([^"]*)".*"port": ([^,]*),.*"instanceNumber":"([^"]*)".*"dbUser":"([^"]*)".*"dbUserPassword":"([^" ]*)".*"sessionId":"([^"]*)".*' [[ $json =~ $regex ]] dbHost=${BASH_REMATCH[1]} dbPort=${BASH_REMATCH[2]} dbInstance=${BASH_REMATCH[3]} P U B L I C 157 dbUser=${BASH_REMATCH[4]} dbPassword=${BASH_REMATCH[5]} tunnelSessionId=${BASH_REMATCH[6]}

hdbsql -n "$dbHost:$dbPort" -i "$dbInstance" -u "$dbUser" -p "$dbPassword" "SELECT * FROM dummy" close-db-tunnel --session-id $tunnelSessionId

i found the above piece of code in persistence service document and it is not working. i adjusted the values but even then it does not work.

can someone help?


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers