database connectivity through C program

Hello everyone

I want to write a program in C so that I can connect through a database just like oracle ,msaccess,mysql
I just used oracle 10g,sqlapi and Code blocks
but it is not working...suggest how to do it.......


the code which i used for this is below

#include <stdio.h>
#include "C:\SQLAPI\include\SQLAPI.h"
int main(int argc, char* argv[])
{
SAConnection con; // create connection object
try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(
"arvind", // database name
"system", // user name
"jai", // password
SA_Oracle_Client); //client name
printf("We are connected!\n");
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect();
printf("We are disconnected!\n");
}
catch(SAException &x)
{
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
// print error message
printf("%s\n", (const char*)x.ErrText());
}
return 0;
}

Last edited on
closed account (o3hC5Di1)
Hi there,

First of all, would you please be so kind to wrap your code in [code]-tags - that makes it more readable for us. [1]

Also, could you clearly describe what it is not doing?
Does the code not compile - if so, which errors do you get?
Does it show unexpected behaviour - if so, what does it do?

That would help us to help you faster :)

Thanks!

NwN


[1]http://cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.