软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络技术 > Linux > 在linux下通过C语言基于freetds连接sql2000

在linux下通过C语言基于freetds连接sql2000

安装好freetds之后
添加库的环境变量
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/
之后开vi
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include </usr/local/freetds/include/sybfront.h>
#include </usr/local/freetds/include/sybdb.h>
void echo(char *str)
{
printf("%s\n",str);
}
int main(void)
{
char uname[32] = "sa";
char upass[32] = "thisispasswordarea";
char server[32] = "222.222.222.222:1678";
dbinit();
LOGINREC *loginrec = dblogin();
DBSETLUSER(loginrec,uname);
DBSETLPWD(loginrec,upass);
DBPROCESS *dbprocess = dbopen(loginrec,server);
echo("connecting...");
if(dbprocess == FAIL)
{
echo("connect...fail");
return 0;
}
if(dbuse(dbprocess,"db_6930") == FAIL)
{
echo("database select fail");
return 0;
}
else
{
echo("connect success.");
dbcmd(dbprocess,"select top 10 userid from wells.dbtest.dbo.user0");
if(dbsqlexec(dbprocess) == FAIL){
echo("query fail...");
return 0;
}
DBINT result_code;
char uid[20];
char nickname[100];
char email[200];
int rows = 0;
while((result_code = dbresults(dbprocess))!= NO_MORE_RESULTS)
{
if(result_code == SUCCEED)
{
dbbind(dbprocess,1,CHARBIND,(DBINT)0,(BYTE*)uid);
while(dbnextrow(dbprocess) != NO_MORE_ROWS)
{
rows++;
echo(uid);
}
}
}
printf("final row=%d\n",rows);
}
dbclose(dbprocess);
echo("connect closed.");
return 0;

}
存为emailParser.c
编译命令==============================
gcc emailParser.c -L/usr/local/freetds/lib -lsybdb
执行=========================
./a.out
输出================================
connecting...
connect success.
358568
358569
358570
358571
358572
358573
358574
358575
358576
358577
final row=10
connect closed.
==================
    相关阅读
    栏目导航
    推荐软件