#include <stdio.h>
#include "/home/mysql/include/mysql.h"
int main()
{
MYSQL mysql
MYSQL_RES *result=NULL
MYSQL_FIELD *field=NULL
mysql_init(&mysql)
mysql_real_connect(&mysql, "localhost", "root", "neusoft", "test", 3306, NULL, 0)
// string sql = "create table a1(col int)"
// mysql_query(&mysql,"insert into a values(3)")
mysql_query(&mysql,"select col from a")
result=mysql_store_result(&mysql)
int fieldcount = mysql_num_fields(result)
MYSQL_ROW row
row = mysql_fetch_row(result)
while(NULL != row)
{
for(int i=0i<fieldcounti++)
{
//field=mysql_fetch_field_direct(result,i)
//printf("%s",row[i])
std::cout<<row[i]<<std::endl
}
//std::cout<<std::endl
row = mysql_fetch_row(result)
}
//mysql_query(&mysql,sql.c_str())
mysql_close(&mysql)
}
这是我成功 *** 作的代码。。。。。
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF") //要写在一行,很重要,主要的问题都在这#include <stdio.h>
void main()
{
_ConnectionPtr cn
::CoInitialize(NULL)
cn.CreateInstance(__uuidof(Connection))
_bstr_t connStr = "Provovider = Microsoft.Jet>OLEDB.4.0Data Source=test.mdb"
try
{
cn->CursorLocation=adUseClient
cn->Open(connStr,"","",adModeUnknown)
_variant_t rowsAffected//影响行数
_RecordsetPtr rs
rs = cn->Execute("SELECT * FROM T_person",&rowsAffected,adCmdText)
while(!rs->adoEOF) //不能有引号
{
_variant_t var = rs->Fields->Item["uid"]->Value
printf("%s\n",(char *)_bstr_t(var))
rs->MoveNext()
}
rs->Close() //close的第一个字母要大写
}
catch(_com_error e)
{
printf("%s\n",(char *)e.Description())
}
if(cn->State) cn->Close()
::CoUninitialize()
exit(0)
}
//PS:stdio.h换回去
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)