C语言 调用DB2接口,有没有小例子,或者文档,链接也行。我这边环境是win7 db2 10.5.0 调用的是DB2官方例子,没能调通,是不是数据库需要配置什么的,谢谢!
我给你一个例子,比如有一段代码:
#include
EXEC SQL INCLUDE SQLCA;
main(void)
{
EXEC SQL connect to test;
EXEC SQL update t3 set name=2;
EXEC SQL commit;
printf(\"SQLCODE:%d\n\",SQLCODE);
}
先把它保存成test.sqc文件,然后运行:
预编译:
db2 prep test.sqc bindfile
[db2inst1@tiger sqc]$ ls
test.bnd test.c test.sqc
编译:
[db2inst1@tiger sqc]$ cc -c test.c
[db2inst1@tiger sqc]$ ls
test.bnd test.c test.o test.sqc
链接:
[db2inst1@tiger sqc]$ gcc -I/home/db2inst1/sqllib/include -o test test.o -L /home/db2inst1/sqllib/lib -ldb2
[db2inst1@tiger sqc]$ ls
test test.bnd test.c test.o test.sqc
绑定:
[db2inst1@tiger sqc]$ db2 connect to test
[db2inst1@tiger sqc]$ db2 bind test.bnd
在linux上运行,可能会涉及到一些gcc的运行环境,需要你对linux和gcc有一个基本的了解。你先试一下,有问题再提出来。