简体   繁体   中英

How do I connect to IBM Db2 Event Store from a C program?

I would like to be able to connect to an IBM Db2 Event Store instance from a C program. I see in the documentation that it supports standard Db2 JDBC connectivity https://www.ibm.com/support/knowledgecenter/SSGNPV_2.0.0/develop/dev-guide.html . Does it also support ODBC and the standard Db2 CLI?

I found the following example https://github.com/IBMProjectEventStore/db2eventstore-IoT-Analytics/tree/master/AdvancedApplications/ODBCApplication

From the example it looks like it is using the SQLDriverConnect API to connect, and it provides it the certificate downloaded by this script https://github.com/IBMProjectEventStore/db2eventstore-IoT-Analytics/blob/master/container/setup/setup-ssl.sh

/* connect to a database with additional connection parameters
   using SQLDriverConnect() */
int DbDriverConnect(SQLHANDLE henv,
                    SQLHANDLE *hdbc, 
                    char dbAlias[],
                    char user[],
                    char pswd[],
                    char hostip[],
                    char port[],
                    char sslcert[])
{
  SQLRETURN cliRC = SQL_SUCCESS;
  int rc = 0;
  SQLCHAR connStr[255];

  printf("\n-----------------------------------------------------------");
  printf("\nUSE THE CLI FUNCTIONS\n");
  printf("  SQLAllocHandle\n");
  printf("  SQLSetConnectAttr\n");
  printf("  SQLDriverConnect\n");
  printf("TO CONNECT TO EVENTSTORE:\n");

  /* allocate a database connection handle */
  cliRC = SQLAllocHandle(SQL_HANDLE_DBC, henv, hdbc);
  ENV_HANDLE_CHECK(henv, cliRC);

  printf("\n  Connecting to the database %s ...\n", dbAlias);

  /* parse connection string */
  sprintf((char *)connStr,
          "DATABASE=%s; UID=%s; PWD=%s; "
          "Protocol=tcpip; Authentication=GSSPLUGIN; "
          "Security=ssl; SSLServerCertificate=%s; "
          "HOSTNAME=%s; PORT=%s;",
          dbAlias, user, pswd, sslcert, hostip, port);

  /* connect to a data source */
  cliRC = SQLDriverConnect(*hdbc,
                           (SQLHWND)NULL,
                           connStr,
                           SQL_NTS,
                           NULL,
                           0,
                           NULL,
                           SQL_DRIVER_NOPROMPT);
  DBC_HANDLE_CHECK(*hdbc, cliRC);

  printf("  Connected to the database %s.\n", dbAlias);
  return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM