OCI 编程⾃学与归纳(⼆)
.
errcode; cout << "Oracle server attach error:" << errbuf << endl;
OCIHandleFree((dvoid *)envhpp,OCI_HTYPE_ENV); OCIHandleFree((dvoid *)servhpp,OCI_HTYPE_SERVER); OCIHandleFree((dvoid
自学编程的书籍*)errhpp,OCI_HTYPE_ERROR);exit(1);}cout << "Oracle server attach success!"<< endl;string user = "tzos";string pas = "tzos";errhpp = NULL;// 发⽣⼀个指定环境的讹谬句柄(void) OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&errhpp, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0);// 发⽣⼀个指定环境的服务上下⽂句柄(void)
OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&svchpp, OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **)0);// 为指定的句柄及描写符设置特定的属性(为服务句柄指定服务上下⽂)(void) OCIAttrSet((dvoid *)svchpp, OCI_HTYPE_SVCCTX, (dvoid *)servhpp, (ub4)0, OCI_ATTR_SERVER, (OCIError *)errhpp);// 发⽣⼀个指定环境的⽤户连接句柄(void) OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&usrhpp, (ub4)OCI_HTYPE_SESSION, (size_t) 0, (dvoid **)0);// 为⽤户连接句柄设置登录名及密码(void) OCIAttrSet((dvoid *)usrhpp, (ub4)OCI_HTYPE_SESSION, (dvoid *)user.c_str(), (ub4)strlen(user.c_str()), (ub4)OCI_ATTR_USERNAME, errhpp);(void) OCIAttrSet((dvoid *)usrhpp, (ub4)OCI_HTYPE_SESSION, (dvoid *)pas.c_str(), (ub4)strlen(pas.c_str()), (ub4)OCI_ATTR_PASSWORD, errhpp);// 认证⽤户再发⽣⼀个会话连接 if(OCISessionBegin(svchpp, errhpp, usrhpp, OCI_CRED_RDBMS,
(ub4)OCI_DEFAULT) != OCI_SUCCESS){int errcnowww.dougg1.info;char errbuf[512]={'/0'};sb4 errcode;// 归来⼀个讹谬指针和⼀个OCI 讹谬代码 OCIErrorGet((dvoid *)errhpp, (ub4)1, (text *)NULL, &errcode, (ub1 *)errbuf, (ub4)sizeof(errbuf),
OCI_HTYPE_ERROR); errcno = errcode; cout << "User session error:" << errbuf << endl; OCIHandleFree((dvoid *)errhpp,OCI_HTYPE_ERROR);
OCIHandleFree((dvoid *)usrhpp,OCI_HTYPE_SESSION); OCIHandleFree((dvoid *)svchpp,OCI_HTYPE_SVCCTX);exit(1);}cout << "user session success!" << endl;(void) OCIAttrSet((dvoid *)svchpp, (ub4) OCI_HTYPE_SVCCTX, (dvoid *)usrhpp, (ub4)0, (ub4)OCI_ATTR_SESSION, errhpp);errhpp = NULL;// 创⽴⼀个句⼦句柄if (OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&zq.zqyifengstmthpp,
OCI_HTYPE_STMT, (size_t)0, (dvoid **)0) != OCI_SUCCESS){cout << "Create STMT error !" << endl;exit(1);}cout << "Create stmt success !" << endl;// 发⽣⼀个指定环境的讹谬句柄 // 为什么万⼀不加这句就会揭⽰指定SQL 语句时就会揭⽰讹谬
呢?OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&errhpp, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0);// 指定会话的SQL 厉⾏语句char sql[255] = {'/0'};sprintf(sql, "%s", "SELECT ID,NAME,/to_char(D
ATE, 'yyyy-mm-dd hh24:MI:SS') as DATE FROM STUDENT ");if (OCIStmtPrepare(stmthpp, errhpp, (text *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT) != OCI_SUCCESS){cout << "Create prepare error!" << sql << endl;exit(1);}cout << "Create prepare success!" << endl;// 申请绑定字段的句柄OCIDefine *bhp1 = NULL;OCIDefine *bhp2 = NULL;OCIDefine *bhp3 = 万⼀你定然改换⼀个String 对象的内容,你该当利⽤StringBuffer 。下⾯的代码会正常⼯作:⽂件收缩的原理(⽹上搜查).
数据库设计过程(续2).
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论