连接到c++中的sql?
我想使用 C++ 连接到 sql。
我的 UNIX 计算机上安装了 g++ (sparc-sun-solaris2.10-g++),sql 版本是 SQL*Plus:版本 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;
}
I want to connect to sql using c++.
I have g++ (sparc-sun-solaris2.10-g++) installed on my UNIX machine and the sql version is SQL*Plus: Release 10.2.0.4.0.
I want to write a c++ code by which I want to connect to sql.
Using shell script I can easily connect to the DB but using c++ I don't know how to do it.
Thanks .
I have this piece of code but this is failing while I compile :
error :
Creating library libr9.so 20110308_083331
ld: fatal: file /tlmsr1/tlm/rt/kimi/proj/c9rprOG/crp/templates.a: open failed: No such file or directory
ld: fatal: file /tlmsr1/tlm/rt/kimi/proj/c9rprOG/crp/templates.a: open failed: No such file or directory
ld: fatal: File processing errors. No output written to /tlmsr1/tlm/rt/kimi/proj/c9rprOG/lib/libcrpr9.so
gmake: * [libr9.so] Error 1
code :
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因为当您说 sql 时,您似乎指的是 Oracle 我认为您想尝试
OCCI
。在这种情况下,此链接可能会有所帮助。但是...使用 OCCI 与通过
SQL*Plus
使用 shell 脚本连接到 Oracle 完全不同。Since it seems as though you mean Oracle when you say sql I think you want to try
OCCI
. In that case this link might help.But... using OCCI is quite different from connecting to Oracle with a shell script via
SQL*Plus
.您也可以看一下这两个库。
OTL 和 SOCI。
我在一些项目中使用了这两种方法,并且它们对我来说效果很好。
You might also take a look at those two libs.
OTL and SOCI.
I used both in some projects and they worked fine for me.
您需要使用 ODBC 库来连接 RDBMS 并从中检索数据。 这似乎是一个很好的起点。
You need to use ODBC libraries to connect and retrieve data from a RDBMS. This seems to be a good starting point.
尝试名为 CDatabase 的类。
创建与数据库的连接。
还有一个名为 ExecuteSQL() 的函数,您可以使用它执行查询。
为了获取结果,你有 CResultSet 类。
如果您发现在这里发帖有困难..我会将样品发送给您。
谢谢
阿伦·P。
Try the class named CDatabase.
Create a connection to the databse.
And a function named ExecuteSQL() using which u can execute queries.
For fetching the results u have CResultSet class.
If you find difficulty post here.. i wil send u the sample.
thanks
Arun P.