64,651
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <occi.h>
#include <sstream>
#include <time.h>
using namespace std;
using namespace oracle::occi;
int main()
{
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
string name = "sys";
string pass = "123";
string srvName = "xxx.xxx.xxx.xxx:1521/ORCL"; //ip是本机的ip地址。
cout << " run to 1 !!!!!!!!" << endl;
Connection *conn = env->createConnection(name,pass,srvName);
cout << " run to 2 !!!!!!!!" << endl;
if(conn) cout << "con suc" << endl;
Statement *stmt = NULL;
string sql = "select table_name from user_tables where rownum<=5";
stmt = conn->createStatement();
stmt->setSQL(sql);
ResultSet *rs = NULL;
rs = stmt->executeQuery();
while(rs->next())
{
cout << "name: " << rs->getString(1) << endl;
}
return 0;
}
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-FEB-2014 18:50:56
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 21-FEB-2014 18:01:47
Uptime 0 days 0 hr. 49 min. 9 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/11g/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/ma/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=222.201.139.194)(PORT=1521))(PROTOCOL_STACK=(PRESENTATION=GIOP)(SESSION=RAW)))
Services Summary...
Service "ORCL.LOCAL" has 1 instance(s).
Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully