C++通过OCCI操作Oracle数据库详解
来源:互联网 发布:河南化工网软件 编辑:程序博客网 时间:2024/06/06 07:51
HelloOracle.cpp
main.cpp
#include <iostream>#define LINUXOCCI //避免函数重定义错误#include <occi.h>using namespace std;using namespace oracle::occi;#pragma comment(lib,"E:\\app\\Administrator\\product\\11.2.0\\dbhome_2\\OCI\\lib\\MSVC\\oci.lib")#pragma comment(lib,"E:\\app\\Administrator\\product\\11.2.0\\dbhome_2\\OCI\\lib\\MSVC\\oraocci11.lib")int mainBak(){ Environment *env=Environment::createEnvironment(Environment::DEFAULT); cout<<"success"<<endl; string name = "scott"; string pass = "tiger"; string srvName = "127.0.0.1:1521/orcl"; try { Connection *conn = env->createConnection(name, pass); cout<<"conn success"<<endl; env->terminateConnection(conn); } catch(SQLException e) { cout<<e.what()<<endl; return -1; } Environment::terminateEnvironment(env); cout<<"end!"<<endl; return 0;}/*successconn successend!请按任意键继续. . .*/
</pre><pre name="code" class="cpp">
</pre><p></p><p>Employees.h</p><p><pre name="code" class="cpp">//Employees.h//复制代码/** A simple OCCI test application* This file contains the Employees class declaration*/#include <iostream>#include <occi.h>#include <iomanip> using namespace oracle::occi;using namespace std;class Employees {public: Employees(); virtual ~Employees(); void List();private: Environment *env; Connection *con; string user; string passwd; string db; };
#include "Employees.h" Employees::Employees() { /* 69 * connect to the test database as the HR 70 * sample user and use the EZCONNECT method 71 * of specifying the connect string. Be sure 72 * to adjust for your environment! The format 73 * of the string is host:port/service_name 74 */ user = "scott"; passwd = "tiger"; db = "127.0.0.1:1521/orcl"; env = Environment::createEnvironment(Environment::DEFAULT); try { con = env->createConnection(user, passwd, db); } catch (SQLException& ex) { cout << ex.getMessage(); exit(EXIT_FAILURE); }} Employees::~Employees() { env->terminateConnection (con); Environment::terminateEnvironment (env); } void Employees::List(){ /*104 * simple test method to select data from105 * the employees table and display the results106 */ Statement *stmt = NULL; ResultSet *rs = NULL; string sql = "select EMPNO, ENAME, JOB " \ "from EMP order by EMPNO"; try { stmt = con->createStatement(sql); } catch (SQLException& ex) { cout << ex.getMessage(); } if (stmt) { try { stmt->setPrefetchRowCount(32); rs = stmt->executeQuery(); } catch (SQLException& ex) { cout << ex.getMessage(); } if (rs) { cout << endl << setw(8) << left << "EMPNO" << setw(22) << left << "ENAME" << setw(27) << left << "JOB" << endl; cout << setw(8) << left << "======" << setw(22) << left << "====================" << setw(27) << left << "=========================" << endl; while (rs->next()) { cout << setw(8) << left << rs->getInt(1) << setw(22) << left << (rs->isNull(2) ? "n/a" : rs->getString(2)) << setw(27) << left << rs->getString(3) << endl <<"-----------------------------------------"<<endl; //<< endl;//cout<<"-----------------------------------------"<<endl; } cout << endl; stmt->closeResultSet(rs); } con->terminateStatement(stmt); } }
main.cpp
#include "Employees.h" using namespace std; using namespace oracle::occi; int main (void) { /* 48 * create an instance of the Employees class, 49 * invoke the List member, delete the instance, 50 * and prompt to continue... 51 */ Employees *pEmployees = new Employees(); pEmployees->List(); cout << "ENTER to continue..."; cin.get(); delete pEmployees; return 0; }
0 0
- 通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- C++通过OCCI操作Oracle数据库详解
- 通过OCCI操作Oracle数据库详解
- Oracle数据库操作(OCCI方式)
- 通过OCCI连接oracle(C++)
- Linux下OCCI操作Oracle数据库
- C++使用oracle的occi库操作oracle数据库
- C++使用oracle的occi库操作oracle数据库
- C++使用oracle的occi库操作oracle数据库
- OCCI连接Oracle数据库
- 通过JDBC操作ORACLE数据库实例详解
- Linux下C连接Oracle数据库OCCI的若干问题
- 构造函数 & main函数
- 深入理解block
- linux权限含义
- 常用的正则表达式收集
- Linux进程间通信之消息队列
- C++通过OCCI操作Oracle数据库详解
- Github 修正上传时“this exceeds GitHub’s file size limit of 100 MB”错误
- ShareSDK [iOS常见问题] 关于使用QQ做第三方登录的问题!
- 对List共用分页
- 使用Apriori算法进行关联分析--代码学习
- uva757
- Fedor and New Game
- HttpWatchPro-ha-crack抓包器怎么没有中文版本
- 每日一vim(0)