gpt4 book ai didi

c++ - 尝试使用 OTL 连接到我的 PostgreSQL 服务器

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:58:27 24 4
gpt4 key购买 nike

我正在尝试将我的 C++ 客户端连接到 PostgreSQL 数据库。我不断收到 otlv4.h|12406|undefined reference to `SQLFreeHandle@8' 和许多其他 undefined reference 错误。

要获取头文件,请转到 http://otl.sourceforge.net/otl3_down.htm

#include <iostream>

using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// #define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used
#define OTL_ODBC_ALTERNATE_RPC
#if !defined(_WIN32) && !defined(_WIN64)
#define OTL_ODBC
#else
#define OTL_ODBC_POSTGRESQL // required with PG ODBC on Windows
#endif
#include "otlv4.h" // include the OTL 4.0 header file

otl_connect db; // connect object

int main()
{

otl_connect::otl_initialize(); // initialize ODBC environment

db.rlogon("postgres/changeme@numbers");

db.commit();

cout << "Hello world!" << endl;

db.logoff(); // disconnect from ODBC
return 0;
}

最佳答案

当我使用 ODBC 从 Windows 连接到 PostgreSQL 时,我使用了无 DSN 的方法。从用户的角度来看,它需要零输入——用户不需要知道什么是 ODBC 以及如何配置 ODBC 源 (DSN)。

使用无 DSN 连接的典型方法是使用如下字符串作为 ODBC 连接字符串:

Driver=PostgreSQL;Server=hostname;Database=mypgdb;UID=username;PWD=password

请注意,可能需要根据版本和 ANSI 与 Unicode 风格调整驱动程序名称。

关于c++ - 尝试使用 OTL 连接到我的 PostgreSQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14009274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com