Once the client software is installed, locate the file hdbcli-x-y-z.tar.gz. The next step is to install the Python hdbcli package. This can be done easily using the Python utility program pip. Execute the following command in a terminal.
pip install /path/to/hdbcli-x-y-z.tar.gz
After the process completes, the Python hdbcli package will be installed. Listing 1 below shows a simple script that tests the database connection.
Listing 1
from hdbcli import dbapi
connection = dbapi.connect("SERVER_HOST", PORT_NUMBER, "USERNAME", "PASSWORD")
print(connection.isconnected())
Replace the connect arguments to reflect your own systems credentials. The SERVER_HOST can be an IP address or a host name.
The script will print True when a successful connection is made.
Executing Queries
SQL statements are executed on a Cursor object. Listing 2 below shows a simple SQL statement that returns the current date.
Listing 2
...
cursor = connection.cursor()
cursor.execute("SELECT NOW() FROM DUMMY")
row = cursor.fetchone()
print(row[0])
Notice on line 2, the cursor() method is used to return a Cursor object. This object is then used to execute SQL statements.
The execute() method returns a Boolean value indicating if the statement executed successfully. The Cursor object exposes several methods to return data. The fetchone() method is used to return a single row while fetchall() returns multiple rows.
- 
                                            JSON_TABLE Function
                                            In this article, we'll take a look at how to use the ++JSON_TABLE++ function to represent JSON data stored in a regular column as a relational table. 31 March 2023 - 4398 views
- 
                                            Connect To HANA DB Using Rust
                                            Learn how to connect and query a HANA database using Rust with the hdbconnect package. 21 February 2023 - 3739 views
- 
                                            If Table Exists Function
                                            In this article, I explain how to create a function to determine if a table exists in SAP HANA. 31 October 2019 - 10005 views
- 
                                            Connect To HANA DB Using NodeJs
                                            This article explains how to connect to a SAP HANA system using the Node HANA client library. 28 October 2019 - 8263 views
- 
                                            Adding Auto Numbers To Table Columns
                                            This article explains how to create an auto generated column using IDENTITY. 14 March 2018 - 7552 views
- 
                                            Connecting To SAP HANA Using PHP ODBC
                                            This article describes how to install and configure PHP odbc to connect to a SAP HANA system on Ubuntu 16. 01 December 2017 - 8656 views
- 
                                            Connect To HANA DB Using Java
                                            This article describes how to connect to a HANA DB system using the ngdbc.jar Java driver. 03 November 2017 - 5979 views
