#include
#include
void Error(char *s);
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
double zip_ID;
char Code_Name[ZC_NAME_LEN+1];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
char user[10]="bank";
char passwd[10]="bank";
EXEC SQL CONNECT :username IDENTIFIED BY :password;
EXEC SQL INSERT INTO ZIP_CODE (ZC_CODE_ID, ZC_CODE_NAME)
values(:zip_ID, :Code_Name);
return 0;
sqlerr:
Error("ZipCode insert error");
}
void Error(char *s)
{
size_t buf_len, msg_len;
char err_msg [513];
err_msg[512]='\0';
printf( "SQL Error %ld : %s\n%s\n", sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc,s);
buf_len = sizeof(err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("Detail error massage: %.*s\n", msg_len, err_msg);
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK RELEASE;
exit( -1 );
}
-----------------------------------------------------------------------------------
参考资料:Pro*c 介绍-内嵌SQL
阅读(1234) | 评论(0) | 转发(0) |