当时看的这篇博客很不错,先收藏。
http://blog.csdn.net/xiaobai1593/article/details/6671722
接下来是我自己总结的:
#include<stream.h>
#include<string.h>
#include<occi.h>
int main()
{
Environment *env;
Connection *con;
Statement *state;
string username="admin";
string pwd="123";
string db="123.123.123.123:1521/db"; //要查询的数据库地址和名字
*env = Environment::createEnvironment(Environment::Default);
*con = env->createConnection(username,pwd,db);
string sql = "select * from users"; //要查询的表
*state = con->createStatement(sql);
ResultSet *result = state->executeQuery();
while(result->next()) //将表内的信息查询出来
{
int id=result->getInt(0);
string username=result->getString(1);
}
state->closeResultSet(result);
con->terminateStatement(state);
env->terminateConnection(con);
Environment::terminateEnvironment(env);
return 0;
}