开发者

connect to sql in c++?

开发者 https://www.devze.com 2023-02-15 01:51 出处:网络
I want to开发者_StackOverflow社区 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开发者_StackOverflow社区 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;
}


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.


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.


You need to use ODBC libraries to connect and retrieve data from a RDBMS. This seems to be a good starting point.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消