【发布时间】:2019-10-07 00:06:22
【问题描述】:
我希望能够从 C 程序连接到 IBM Db2 Event Store 实例。我在文档中看到它支持标准 Db2 JDBC 连接https://www.ibm.com/support/knowledgecenter/SSGNPV_2.0.0/develop/dev-guide.html。它还支持 ODBC 和标准 Db2 CLI 吗?
【问题讨论】:
标签: c db2 ibm-event-store
我希望能够从 C 程序连接到 IBM Db2 Event Store 实例。我在文档中看到它支持标准 Db2 JDBC 连接https://www.ibm.com/support/knowledgecenter/SSGNPV_2.0.0/develop/dev-guide.html。它还支持 ODBC 和标准 Db2 CLI 吗?
【问题讨论】:
标签: c db2 ibm-event-store
从示例中可以看出它正在使用 SQLDriverConnect API 进行连接,并为它提供了此脚本下载的证书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;
}
【讨论】: