日期:2014-05-16  浏览次数:20438 次

Linux c 查询Oracle数据库例子
/* 
 * File:   main.c
 * Author: oracle
 *
 * Created on October 11, 2012, 3:14 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include "sqlora.h"
/*
 * 
 */
int main(int argc, char** argv) {

sqlo_db_handle_t dbh;
int sd;
int sth;

const char *cstr = "xia/pass123@DBInstance";
const char **v;


if (SQLO_SUCCESS != sqlo_init(SQLO_OFF,1,100))                    

{    
        printf ("sql_init failed. Exiting\n");  
        exit(1);  
}  


if (SQLO_SUCCESS != sqlo_connect(&dbh, cstr)){
        printf ("connect failed. Exiting\n");  
        exit(1); 
}else
{
        printf ("connect successfully. Exiting\n");  
}


char *select_stmt="SELECT * FROM status";  

if (0>(sd=sqlo_open(dbh, select_stmt, 0, NULL)))  
{   

        printf("open table failed: %s\n", sqlo_geterror(dbh));  
        return 0;  

}
else
{
        printf("open table");
}
printf("\n");
while(0==sqlo_fetch(sd,1)){
    
    v=sqlo_values(sd,NULL,1);
    printf("Result is : %s %s %s %s %s %s\n",v[0],v[1],v[2],v[3],v[4],v[5]);
}
sqlo_finish(dbh);
return (EXIT_SUCCESS);

}