-
-
Save icsaas/a6750019009d65e80cb1 to your computer and use it in GitHub Desktop.
occi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OracleTest.cpp : 定义控制台应用程序的入口点。 | |
// | |
#include "stdafx.h" | |
#include "iostream" | |
#include <occi.h> | |
#pragma comment(lib,"oraocci11.lib") | |
using namespace oracle::occi; | |
using namespace std; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
try | |
{ | |
const string userName = "SYSTEM"; | |
const string password = "wxw"; | |
const string connectString= "//localhost:1521/xe"; | |
unsigned int maxConn=5; | |
unsigned int minConn=1; | |
unsigned int incrConn=2; | |
oracle::occi::Environment *env = oracle::occi::Environment::createEnvironment("ZHS16GBK","UTF8"); | |
//建立连接池 | |
ConnectionPool *connPool=env->createConnectionPool( | |
userName, | |
password, | |
connectString, | |
minConn, | |
maxConn, | |
incrConn); | |
//从连接池获取连接 | |
Connection *conn=connPool->createConnection(userName,password); | |
Statement *stmt = conn->createStatement("select * from userinfo"); | |
ResultSet *rs = stmt->executeQuery(); | |
while (rs->next()) | |
{ | |
string l1=rs->getString(1); | |
string l2=rs->getString(2); | |
string l3=rs->getString(3); | |
cout <<"用户ID"<<l1<<" 用户姓名:"<<l2<<" 用户地址:"<<l3<<endl; | |
} | |
stmt->closeResultSet(rs); | |
conn->terminateStatement(stmt); | |
connPool->terminateConnection(conn); | |
//释放连接 | |
env->terminateConnectionPool(connPool); | |
//env->terminateConnection(conn); | |
oracle::occi::Environment::terminateEnvironment(env); | |
} | |
catch (SQLException &sqlExcp) | |
{ | |
int i=sqlExcp.getErrorCode(); | |
string strinfo=sqlExcp.getMessage(); | |
cout<<strinfo; | |
} | |
int i; | |
cin>>i; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment