亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2564 | 回復(fù): 2
打印 上一主題 下一主題

[C++] 用過OCCI的進(jìn)來解答啊。 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-07-07 16:36 |只看該作者 |倒序?yàn)g覽
我運(yùn)行demo的一段程序OCCI方式連接TimesTen11.2數(shù)據(jù)庫,運(yùn)行結(jié)果如下: 。不知道是否正確啊,貌似不對~~

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2011-07-07 16:38 |只看該作者
源程序如下:
#include <iostream>
#include <occi.h>
using namespace oracle:cci;
using namespace std;

class  test
{
  private:

  Environment *env;
  Connection *conn;
  Statement *stmt;
  public:

  test (string user, string passwd, string db)
  {
    env = Environment::createEnvironment (Environment:EFAULT);
    conn = env->createConnection (user, passwd, db);
  }

  ~test ()
  {
    env->terminateConnection (conn);
    Environment::terminateEnvironment (env);
  }
/***insert***/
void insertRow ()
  {
    string sqlStmt = "INSERT INTO author_tab VALUES (001, 'first')";
    stmt = conn->createStatement (sqlStmt);
    try{
    stmt->executeUpdate ();
    cout << "insert - Success!" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for insertRow"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
/***delete***/
void deleteRow (int c1, string c2)
  {
    string sqlStmt =
      "DELETE FROM author_tab WHERE author_id= AND author_name = :y";
    stmt = conn->createStatement (sqlStmt);
    try{
    stmt->setInt (1, c1);
    stmt->setString (2, c2);
    stmt->executeUpdate ();
    cout << "delete - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for deleteRow"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
/***update***/
void updateRow (int c1, string c2)
  {
    string sqlStmt =
      "UPDATE author_tab SET author_name = WHERE author_id = :y";
    stmt = conn->createStatement (sqlStmt);
    try{
    stmt->setString (1, c2);
    stmt->setInt (2, c1);
    stmt->executeUpdate ();
    cout << "update - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for updateRow"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
/***displey***/
void displayAllRows ()
  {
    string sqlStmt = "SELECT author_id, author_name FROM author_tab \
    order by author_id";
    stmt = conn->createStatement (sqlStmt);
    ResultSet *rset = stmt->executeQuery ();
    try{
    while (rset->next ())
    {
      cout << "author_id: " << rset->getInt (1) << "  author_name: "
        << rset->getString (2) << endl;
    }
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for displayAllRows"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    stmt->closeResultSet (rset);
    conn->terminateStatement (stmt);
  }
};//end test
/***main***/
int main (void)
{
string user="ttadmin";
string passwd="ttadmin";
string db ="";
try{
  cout << "Test - Exhibiting simple insert, delete & update operations"
       << endl;
  test *demo = new test (user, passwd, db);
cout << "Displaying all records before any operation" << endl;
  demo->displayAllRows ();

cout << "Inserting a record into the table author_tab "
    << endl;
  demo->insertRow ();

cout << "deleting a row with author_id as 222 from author_tab table" << endl;
  demo->deleteRow (01, "first";

cout << "updating a row with author_id as 444 from author_tab table" << endl;
  demo->updateRow (02, "new";

cout << "Displaying all records again" << endl;
  demo->displayAllRows ();

delete (demo);
  }
  catch (SQLException ex){
    cout << ex.getMessage() << endl;
  }
  cout << "Test - done" << endl;
}
求高手解答!非常感謝!小弟剛?cè)腴T~

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-07-07 16:38 |只看該作者
提示很明顯啊,你的tns名指定錯(cuò)了。

string db ="";
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP