我想使用 C++ 连接到 sql。
我在我的 UNIX 机器上安装了 g++ (sparc-sun-solaris2.10-g++),sql 版本是 SQL*Plus: Release 10.2.0.4.0。
我想编写一个 c++ 代码,通过它连接到 sql。
使用 shell 脚本我可以很容易地连接到数据库,但是使用 c++ 我不知道该怎么做。
谢谢。
我有这段代码,但是在我编译 时失败了:
错误:
正在创建库 libr9.so 20110308_083331
ld: fatal: file/tlmsr1/tlm/rt/kimi/proj/c9rprOG/crp/templates.a: 打开失败:没有这样的文件或目录 ld:致命:文件/tlmsr1/tlm/rt/kimi/proj/c9rprOG/crp/templates.a:打开失败:没有这样的文件或目录 ld:致命:文件处理错误。没有输出写入/tlmsr1/tlm/rt/kimi/proj/c9rprOG/lib/libcrpr9.so gmake: * [libr9.so] 错误 1
代码:
#include <stdlib.h>
#include <occi.h>
#include <iostream>
using namespace oracle::occi;
using namespace std;
class testOcci
{
private:
Environment *env;
Connection *conn;
public:
testOcci (string user, string passwd, string db)
{
env = Environment::createEnvironment (Environment::DEFAULT);
conn = env->createConnection (user, passwd, db);
}
/**
* Destructor for the occi test case.
*/
~testOcci ()
{
env->terminateConnection (conn);
Environment::terminateEnvironment (env);
} // end of ~testOcci ()
};
int main(void)
{
string user="sbsdb6";
string passwd="sbsdb6";
string db="ABPDV";
testOcci *demo = new testOcci (user, passwd, db);
cout << "Creation Successful" << endl;
delete (demo);
cout << "Deletion Successful" << endl;
return 0;
}
最佳答案
当你说 sql 时,你似乎指的是 Oracle 我想你想试试 OCCI
。在那种情况下 this link可能有帮助。
但是...使用 OCCI 与通过 SQL*Plus
使用 shell 脚本连接到 Oracle 是完全不同。
关于c++ - 在 C++ 中连接到 sql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5219195/