设置Linux-C-DB2环境 [英] Setting up Linux-C-DB2 environment

查看:120
本文介绍了设置Linux-C-DB2环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个学习环境:编写和测试简单的C程序以在Ubuntu 18.04上执行DB2数据库操作。

I'm trying to set up an environment for learning: writing and testing simple C programs to perform DB2 database operations on an Ubuntu 18.04. system.

我在Web教程和IBM页面的帮助下安装了DB2,从安装程序接收了数据库信息,并在Gedit中编写了简单的程序。

I installed DB2 with help of web tutorials and IBM pages, received database info from the installer, wrote simple programs in Gedit..

我使用Gnu C编译器(gcc)编译了最简单的程序。

I compiled the simplest programs with Gnu C Compiler (gcc).

编译器遇到 EXEC SQL ... 行终止并报告了错误。

As soon as the compiler ran into the "EXEC SQL..." line it terminated and reported an error.

使此功能正常工作的下一步是什么?

What's my next step in making this thing work?

推荐答案

以下是不错的入门文章之一:



[Db2]在Linux上编译一个简单的C应用程序以验证环境

https://www.ibm.com/support/pages/db2-compile-simple-c-application-linux-verify-environment

Here is one of nice starting point articles:

[Db2] Compile a simple C application on Linux to verify environment
https://www.ibm.com/support/pages/db2-compile-simple-c-application-linux-verify-environment

它是为RHEL 7.6和CentOS 7编写的。但是它应该可以与ubuntu一起使用。

It was written for RHEL 7.6 and CentOS 7. But it should work with ubuntu.

... snip ...

select.sqc.
-----
#include <stdio.h>
#include <string.h>
#include <sqlca.h>
#include <sqlenv.h>
#include <sqlutil.h>
int main(int argc, char *argv[]){
  struct sqlca sqlca;
  EXEC SQL BEGIN DECLARE SECTION;
    char dbAlias[15];
    char deptname[100];
  EXEC SQL END DECLARE SECTION;
  strcpy(dbAlias, argv[1]);
   :
... snip ...



... snip ...

db2 connect to $DBNAME
db2 PREP $CSOURCE.sqc BINDFILE
gcc -I$HOME/sqllib/include -c $CSOURCE.c
gcc -o $CSOURCE $CSOURCE.o -ldb2 -L$HOME/sqllib/lib
db2 bind $CSOURCE.bnd
... snip ...

建议阅读本文并按照步骤操作。

It is recommended to review the article and follow steps.

希望这会有所帮助。

这篇关于设置Linux-C-DB2环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆