Connect from Go to SAP HANA

Use the Go driver to connect to an SAP HANA database.

Prerequisites

You have built the Go driver.

Context

The SAP HANA driver for Go supports all of the SQLDBC connection properties.

You can trace Go connections by using SQLDBC tracing.

Procedure

Connect to the SAP HANA database:
Connection Type Command
Connection string
hdb://<user>:<password>@<host>:<port>?<connection-property>=<value>&<connection-property>=<value>&...

Replace <user> and <password> with the database user and password, and replace <host>:<port> with the SAP HANA server host and port.

hdb://<user>:<password>@<host>:<port> is a valid connection string

The <connection-property> names are case sensitive. Connection properties are not required.

If a property value contains URL special characters (such as providing the full certificate string as the value for the sslTrustStore connect property), URL encode its value. Use the net/url package to do this in one of two ways:

  1. Quoting the specific value:
    encodedValue := url.QueryEscape("<original value>")
  2. Building the entire string via the package:

    connectURL, err := url.Parse(""hdb://<username>:<password>@<hostname>:<port>)
    if err != nil {
    // Report error and return
    }
    params := url.Values{}
    // For each pair of connectProperty=value add like this
    params.Add("<connectProperty>", "<raw value>")
    //...
    // Add the parameters to the URL
    connectURL.RawQuery = params.Encode()
    // The final connect string to be used:
    connectString = connectURL.String()
Tenant database in an MDC system
hdb://<user>:<password>@<host>:<port>?databaseName=<tenant-db-name>

Replace <user> and <password> with the database user and password, and replace <host>:<port> with the SAP HANA server host and port. Replace <tenant-db-name> with the name of the tenant database.

hdbuserstore key
hdb://?key=<keyname>