Connecting to a database

Updated: October 26, 2022

Connecting to a database requires that you know its name so you can specify the correct device name when connecting through the QDB client library. When you call the connect function, the library returns a handle that you can subsequently use for accessing the database:

qdb_hdl_t *dbhandle;  // The QDB database handle 
dbhandle = qdb_connect("/dev/qdb/customerdb", 0);
if (dbhandle == NULL) {
    fprintf(stderr, "Connect failed: %s\n", strerror(errno));
Note: Multiple threads can share a database connection, provided that they coordinate amongst themselves. Alternatively, each thread can call qdb_connect() and have its own connection.