C语言赋值null到db2,C语言调用DB2查询数据插入结构体的问题

#include EXEC SQL INCLUDE sqlca;

int main(void)

{

EXEC SQL BEGIN DECLARE SECTION;

struct ST_OUTPUT

{

long id;

char name[201];

char name2[256];

} m_output = {0};

EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT TO DB_t;

EXEC SQL DECLARE C CURSOR FOR

SELECT ID, NAME, NAME2

FROM BACK.TEST_A

WITH UR;

EXEC SQL OPEN C;

if (SQLCODE != 0)

{

printf("~~~~~~ERROR [SQLCODE=%d]\n", SQLCODE);

return -1;

}

while(1)

{

EXEC SQL FETCH C INTO :m_output;

if (SQLCODE != 0)

{

printf("~~~~~~ERROR [SQLCODE=%d]\n", SQLCODE);

break;

}

else

{

printf("~~~~~~[%d][%s][%s]\n", m_output.id, m_output.name, m_output.name2);

}

}

EXEC SQL CLOSE C;

EXEC SQL CONNECT RESET;

return 0;

}

///测试测试

[back@localhost tmp]$ db2 prep main.sqc bindfile

LINE    MESSAGES FOR main.sqc

------  --------------------------------------------------------------------

SQL0060W  The "C" precompiler is in progress.

SQL0091W  Precompilation or binding was ended with "0"

errors and "0" warnings.

[back@localhost tmp]$

[back@localhost tmp]$ db2 bind main.bnd

LINE    MESSAGES FOR main.bnd

------  --------------------------------------------------------------------

SQL0061W  The binder is in progress.

SQL0091N  Binding was ended with "0" errors and "0" warnings.

[back@localhost tmp]$

[back@localhost tmp]$ db2 GRANT EXECUTE ON PACKAGE main to public

DB20000I  The SQL command completed successfully.

[back@localhost tmp]$

[back@localhost tmp]$ gcc -c  -g   -I/home/db2inst1/sqllib/include main.c

[back@localhost tmp]$

[back@localhost tmp]$ gcc -lstdc++ -lm  -L/home/db2inst1/sqllib/lib -ldb2 -o test main.o

/usr/bin/ld: warning: libstdc++.so.5, needed by /home/db2inst1/sqllib/lib/libdb2.so, may conflict with libstdc++.so.6

[back@localhost tmp]$

[back@localhost tmp]$ ./test

~~~~~~[1][abc_abc][abc_abc]

~~~~~~[2][we_dddd][we_dddd]

~~~~~~[3][dgfh_ryuyu][dgfh_ryuyu]

~~~~~~[5][wewerertty][]

~~~~~~ERROR [SQLCODE=100]

[back@localhost tmp]$收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值