c++读取oracle数据库
时间: 2023-11-29 18:04:00 浏览: 34
可以使用Oracle提供的C++库OCCI来读取Oracle数据库。以下是一个简单的示例代码:
```cpp
#include "occi.h"
#include <iostream>
#include <string>
using namespace oracle::occi;
using namespace std;
int testOracle(){
Environment* env;
try {
env = Environment::createEnvironment(Environment::DEFAULT);
cout << "success" << endl;
string name = "root";
string pass = "root";
string srvName = "//171.29.34.41:1521/ORCL";
Connection* conn = env->createConnection(name, pass, srvName);
cout << "conn success" << endl;
Statement* stmt = NULL;
ResultSet* rs = NULL;
string sql = "select \"StorageServerPath\" from \"temp\"";
stmt = conn->createStatement(sql);
rs = stmt->executeQuery();
while (rs->next()) {
cout << rs->getString(1) << endl;
}
env->terminateConnection(conn);
}
catch (SQLException e) {
cout << e.what() << endl;
return -1;
}
Environment::terminateEnvironment(env);
cout << "end!" << endl;
return 0;
}
int main() {
testOracle();
getchar();
return 0;
}
```
该示例代码使用OCCI连接Oracle数据库,并执行了一条查询语句,将结果输出到控制台。你可以根据自己的需求修改代码。