Linux c 更新Oracle数据库
#include <stdio.h> #include <stdlib.h> #include "sqlora.h" /* * */ int main(int argc, char** argv) { sqlo_db_handle_t dbh; const char *cstr = "xia/pass123@TestDB"; 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); } int stat; const char * arg[2]; arg[0] = "1.0"; arg[1] = "2.0"; //VERSION 为 VARCHAR类型,如果是数字类型,也需要加双引号 //arg[0]="33" stat=sqlo_run(dbh,"UPDATE STATUS SET VERSION = :1 where VERSION = :2",2,arg); if (0>stat){ printf("Error happened %s ",sqlo_geterror(dbh)); } stat = sqlo_commit(dbh); sqlo_finish(dbh); return (EXIT_SUCCESS); }
方式二
int stat; stat=sqlo_exec(dbh,"UPDATE TEST SET Age = 39 where ID = 1 and Name='jack'"); if (0>stat){ printf("Error happened %s ",sqlo_geterror(dbh)); } stat = sqlo_commit(dbh);
方式三
int stat; char stmt[1024]; sprintf(stmt,"UPDATE TEST SET Age = 40 where ID = %d and Name = %s",1,"'mike'"); stat=sqlo_exec(dbh,stmt); if (0>stat){ printf("Error happened %s ",sqlo_geterror(dbh)); }
编译
gcc -c -g -I/usr/local/lib/libsqlora8/include -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c gcc -o dist/Debug/GNU-Linux-x86/gcctest build/Debug/GNU-Linux-x86/main.o -L/usr/local/lib -lsqlora8 LD_LIBRARY_PATH=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib export LD_LIBRARY_PATH
生成a.out,运行:./a.out
相关推荐
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
bluecarrot 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20
彼岸随笔 2020-10-20
yutou0 2020-10-17
applecarelte 2020-10-16
ourtimes 2020-10-16
waterhorse 2020-09-19
MRFENGG 2020-11-11
rainandtear 2020-10-30
kyssfanhui 2020-10-20
liuhangtiant 2020-10-20