connecting with database

how to connect c++ with database ? is ther any tool to connect?
raja_nambiAsked:
Who is Participating?
 
nietodCommented:
Standard C++ provides no features for this.

However, many operating systems and/or database management systems do provide ways to do this.  So there may be a way to do this for the OS you are running on or the DBMS you need to use, but we woudl need to know these sorts of details.
0
 
Brain2000Commented:
Are you trying to use ODBC?  If so I have some sample code.
0
 
Brain2000Commented:
Also, what platform?  Windows, Unix?  What OS?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
nietodCommented:
If for windows, I would recommend SQL over ODBC.
0
 
abancroftCommented:
"Recommend SQL over ODBC" doesn't make sense. SQL is a data driven query language - it can't be used directly from C++.

What did you mean to say?
0
 
SDUCommented:
He probably want to mean that ODBC to connect to your database uses SQL under the hood.

Raja Nambi,
Are you using MFC? if yes I agree with nietod, ODBC or DAO are easy way to do what you want.
0
 
nietodCommented:
I mean the SQLxxxx() functions.  AFAIK these will use ODBC or other DB interfaces to communicate with the database.  i.e. they are a higher level of abstraction than ODBC.  Of course none of this matters if this is for a Macintosh, Unix, VAX, etc...
0
 
abancroftCommented:
Such as SQLExecute()? These are the ODBC API functions.

Or is there another set?
0
 
nietodCommented:
This isn't my area of expertise, but I was under the impression that these functions were a level above ODBC.
0
 
abancroftCommented:
Nope - they are ODBC.
0
 
Brain2000Commented:
Moving back a step, you said you can't access SQL directly with C++?  We have libraries that are SQL only that are used with C++ and not ODBC.  I personally prefer using the ODBC method though, so you can map the ODBC directly to and SQL database table or an Access file (if you would want to do such a thing)
0
 
abancroftCommented:
What I meant was: you cannot execute SQL statements in C/C++ code. You have to go through a library that takes the SQL and passes it to the DB engine.

i.e.:
 "SELECT * FROM FOO";
won't do anything - though it will compile.

Perhaps I was being a bit pedantic, but I feel it is best to be explicit when communicating like this.

BTW: ODBC is "SQL only". All data access is done using SQL statments.
0
 
chensuCommented:
For Windows, ActiveX Data Objects (ADO) is the recommended data access technology.
0
 
nietodCommented:
Did you mean to accept my comment as an answer?  It doesn't seem worthy.
0
 
raja_nambiAuthor Commented:
actually iam using windows ,for that i want to connect with database,with odbc i couldn't understand how it can be?
0
 
nietodCommented:
You really shouldn't have accepted my comment as the answer, then, because I'm not really the expert on this one.

but to use ODBC (apparently):

(Corrrect me on this stuff if I'm wrong...)

You 1st need to allocate an environment handle wich stores "settings" about how you want to use ODBC.  You do this with  SQLAllocHandle() specifying a handle type of SQL_HANDLE_ENV.  

Then you need to allocat a handle for the database connection, this handle is used to "interact" with a particular database, again you do this with SQLAllochandle() and SQL_HANDLE_DBC and you will need to specify the environment handle you created in the 1st step.  

Then you need to connect to the database, for this use SQLConnect() with the connection handle you created.

Then you can "interact" with the database using the myriad other SQL functions provided.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.