下面这个代码一直报错error: ld returned 5 exit status 有没有人能帮我看看555
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <odbcss.h>
#include <stdio.h>
SQLHENV henv;//环境句柄
SQLHDBC hdbc;//连接句柄
SQLHSTMT hstmt;//语句句柄
SQLRETURN retcode;//返回值
int main()
{
retcode = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);//分配环境句柄
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);//将第一个参数设置为第二个参数的属性
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);//分配连接句柄
retcode = SQLConnect(hdbc, (SQLCHAR*)"mytest32", SQL_NTS, (SQLCHAR*)"sa", SQL_NTS, (SQLCHAR*)"su011214", SQL_NTS);
//与数据库建立连接。“mytest64”是ODBC中添加的数据源名字,"123456"是我设置的sa密码,根据自己的设置自行修改。SQL_NTS时,您正在告诉编译器,前面的参数是空终止的字符串,请为我计算字符串长度
if (!(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO))
{
printf("连接数据库失败!retcode=%d\n",retcode);
return 0;
}
else
{
printf("connect SQL success!");
}
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
SQLCHAR sql1[] = "use test";//使用名为"TEST"数据库,根据自己创建的数据库名称进行修改
SQLCHAR sql2[] = "select * from StudentInfo";//查询已创建好的名为"StudentInfo"表所有列
retcode = SQLExecDirect(hstmt, sql1, SQL_NTS);//SQLExecDirect,此函数用于执行SQL语句,执行sql1语句,即"use TEST"
retcode = SQLExecDirect(hstmt, sql2, SQL_NTS);//执行sql2语句
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLCHAR str1[50], str2[50], str3[50], str4[50], str5[50];
SQLLEN len_str1, len_str2, len_str3, len_str4, len_str5;
while (SQLFetch(hstmt) != SQL_NO_DATA)
{
SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1);
SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2);
SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3);
SQLGetData(hstmt, 4, SQL_C_CHAR, str4, 50, &len_str4);
SQLGetData(hstmt, 5, SQL_C_CHAR, str5, 50, &len_str5);
printf("\n%s\t%s\t%s\t%s\t%s\n",str1,str2,str3,str4,str5);
}
}
printf("process finish\n");
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);//释放连接句柄
SQLFreeHandle(SQL_HANDLE_ENV, henv);//释放环境句柄
}