[英]connect to sql in c++?
我想使用c ++连接到sql。
我在UNIX计算机上安装了g ++(sparc-sun-solaris2.10-g ++),SQL版本为SQL * Plus:10.2.0.4.0版。
我想编写一个我想通过它连接到sql的c ++代码。
使用shell脚本,我可以轻松地连接到数据库,但是使用c ++,我不知道该怎么做。
谢谢 。
我有这段代码,但是在编译时失败了:
错误:
ld:致命:文件/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
。 在这种情况下, 此链接可能会有所帮助。
但是...使用OCCI与通过SQL*Plus
使用shell脚本连接到Oracle有很大不同 。
您需要使用ODBC库来连接和检索RDBMS中的数据。 这似乎是一个很好的起点。
尝试名为CDatabase的类。 创建到数据库的连接。 还有一个名为ExecuteSQL()的函数,您可以使用它执行查询。 为了获取结果,您具有CResultSet类。 如果您在这里发现困难,请寄样品。
感谢Arun P.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.