求C++连接oracle 数据库的代码

求C++连接oracle 数据库的代码,第1张

#include <DbManagerh>

#include <iostream>

using namespace std;

using namespace oracle::occi;

const string sqlString("select empno, ename from employee");

int main(int argc, char argv)

{

if (argc != 2)

{

cerr << "\nUsage: " << argv[0] << " <db-user-name>\n" << endl;

exit(1);

}

// Initialize OracleServices

DbManager dbm = NULL;

OracleServices oras = NULL;

Statement stmt = NULL;

ResultSet resultSet = NULL;

try

{

// Obtain OracleServices object with the default args

dbm = new DbManager(userName);

oras = dbm->getOracleServices();

// Obtain a connection

Connection conn = oras->connection();

// Create a statement

stmt = conn->createStatement(sqlString);

int empno;

string ename;

// Execute query to get a resultset

resultSet = stmt->executeQuery();

while (resultSet->next())

{

empno = resultSet->getInt(1); // get the first column returned by the query;

ename = resultSet->getString(2); // get the second column returned by the query

if (resultSet->isNull(1))

{

cout << "Employee Number is null " << endl;

}

if (resultSet->isNull(2))

{

cout << "Employee Name is null" << endl;

}

cout << empno << "\t" << ename <<endl;

}

// Close ResultSet and Statement

stmt->closeResultSet(resultSet);

conn->terminateStatement(stmt);

// Close Connection and OCCI Environment

delete dbm;

}

catch (SQLException& ex)

{

if (dbm != NULL)

{

dbm->rollbackActions(ex, stmt, resultSet); // free resources and rollback transaction

}

}

return 0;

}

刚登录上去的时候不就有提示吗?

比如 :

$ sqlplus /nolog

SQLPlus: Release 102010 - Production on Tue Jul 5 10:22:08 2011

Copyright (c) 1982, 2005, Oracle All rights reserved

SQL>

也可以查询v$version表。比如

SQL> select from v$version;

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 102010 - Prod

PL/SQL Release 102010 - Production

CORE 102010 Production

TNS for Linux: Version 102010 - Production

NLSRTL Version 102010 - Production

以上就是关于求C++连接oracle 数据库代码全部的内容,包括:求C++连接oracle 数据库的代码、在oracle的sqlplus中,怎么写代码来查看当前所用的数据库系统的版本、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9745957.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存