日期:2014-05-17 浏览次数:20899 次
#include <iostream>
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main(){
Environment *env;
Connection *conn;
Statement *stmt;
try
{
env = Environment::createEnvironment(Environment::DEFAULT);
conn = env->createConnection("guixh", "guixh","localhost:1521"); //这句抛出异常,异常为24960
stmt = conn->createStatement();
stmt->setAutoCommit(true);
ResultSet *rs = stmt->executeQuery("Select * FROM t1");
while (rs->next())
{
int num = rs->getInt(1);
string name = rs->getString(2);
cout << num << name <<endl;
}
}
catch(SQLException &ex)
{
cout << ex.getErrorCode() << ": " << ex.getMessage() << endl;
}
env->terminateConnection(conn);
conn->terminateStatement(stmt);
return 0;
}