当前位置: 首页 > news >正文

惠州外包网站建设基础建站如何提升和优化

惠州外包网站建设,基础建站如何提升和优化,科技公司取名,wordpress 直播 视频教程文章目录 1 OCCI使用1.1 初始化 - Environment 类1.2 连接数据库 - Connection 类1.3 执行SQL 2 OCCI在项目中的使用2.1 OCCI单独封装为一个类文件OCCIOP2.2 在ServerOP中作为私有成员2.3 ServerOP::ServerOP(string json)中实例化进行使用2.4 秘钥协商过程中进行读写操作 1 OC…

文章目录

  • 1 OCCI使用
    • 1.1 初始化 - Environment 类
    • 1.2 连接数据库 - Connection 类
    • 1.3 执行SQL
  • 2 OCCI在项目中的使用
    • 2.1 OCCI单独封装为一个类文件OCCIOP
    • 2.2 在ServerOP中作为私有成员
    • 2.3 ServerOP::ServerOP(string json)中实例化进行使用
    • 2.4 秘钥协商过程中进行读写操作

1 OCCI使用

// 头文件
#include <occi.h>
// occi的接口类在对应的命名空间中
using namespace oracle::occi;// 使用
1. 初始化一个环境->对应的类: Environment
2. 使用初始化完成的环境对象创建一个连接, 得到一个连接对象: Connection, 通过这个对象可用连接并操作服务器
3. 对数据库的操作: 添删查改(对应相关的sql语句)- 通过得到的连接数据库的实例对象, 创建一个可以对象数据进行sql操作的一个对象: Statement
4. 如果对数据进行是查询操作, 会得到一个结果集, 这个结果集对应的也是一个类: ResultSet
5. 释放资源- 结果集资源->ResultSet- 对数据进行sql操作的对象->Statement- 销毁连接对象->Connection- 数据连接环境->Environment

1.1 初始化 - Environment 类

OCCI通过创建一个Environment的对象完成初始化工作。

可以通过Environment创建数据库连接,从而进行其它的操作

要创建Environment,应该调用Environment类的静态方法createEnvironment()

// 环境初始化
Environment* env = Environment::createEnvironment();
// 关闭, 释放资源
Environment::terminateEnvironment(env);

1.2 连接数据库 - Connection 类

连接数据库通过Connection类的对象实例实现

调用Environment类的**createConnection()**方法可以创建一个Connection对象;

// 函数原型: 
// 连接串格式: IP:端口/数据库实例名
Connection *Environment::createConnection( const string &userName,const string &password, const string &connectString );
// 函数调用
const string userName = "scott";    // 用户名
const string passwd = "tiger";    // 密码
const string connstr = "192.168.247.129:1521/orcl";    // 数据库连接串
Connection* conn = env->createConnection(userName, passwd, connstr);

使用**Environment::terminateConnection()**断开连接

// 断开连接
env->terminateConnection(conn);

1.3 执行SQL

Statement 类用于执行SQL语句,并获取返回结果。

ResultSet 类用于处理SELECT 查询的结果。

对于所有类型的数据的绑定或者获取,OCCI都提供了统一的方法

  • setXXX 方法用于Statement
  • getXXX 方法用于Statement & ResultSet

OCCI会自动处理类型之间的转换。

使用方法:

使用Connection:😗*createStatement()**创建Statement对象, 指定 SQL 命令(DDL/DML/query)作为参数

// 操作函数
Connection::createStatement(string &sql);Statement::setSQL(string &sql);Statement::execute(string &sql);       // can be used for any SQL, returns status
// 执行一个insert/update/delete
Statement::executeUpdate(string &sql); // returns Insert/Update/Delete count
// 执行一个select语句
Statement::executeQuery(string &sql);  // returns ResultSet(结果集)

使用 setXXX 方法传递要绑定用于输入的值

使用合适的execute方法执行SQL

对于SELECT 查询, 使用ResultSet 对象处理返回结果

// 插入操作
Statement *stmt = conn->createStatement(“ insert into Dept(Deptno,Dname, Loc) values (1, ‘ACCOUNTS’, ‘ZONE1’ ”);
stmt->executeUpdate();  
conn->terminateStatement(stmt);       // 关闭查询, 释放资源

使用绑定参数的DML(数据操作语句)示例:

Statement *stmt = conn->createStatement(“ insert into  Emp(EmpNo,Ename) values(:1, :2) ”);  
//1 and 2 are bind placeholders  
int empno = 2;  
string empname = “JOHN W”;  
//first parameter is bind position, second is value  
stmt->setInt(1, empno);   
stmt->setString(2, empname);  
stmt->executeUpdate();  

执行SELECT查询并处理结果:

Statement *stmt = conn->createStatement(“select Empno, Ename, Sal from Emp where Hiredate >= :1”);  //automatically converted to Date  
stmt->setString(1, “01-JAN-1987”);  //executeQuery returns a ResultSet  
ResultSet *rs = stmt->executeQuery();   //ResultSet::next fetches rows and returns FALSE   
//when no more rows  
while (rs->next() == true)  
{  //get values using the getXXX methods of ResultSet  empno = rs->getInt(1);  empname = rs->getString(2);  empsalary = rs->getFloat(3);  
}  
stmt->closeResultSet(rs);//to free resources 

2 OCCI在项目中的使用

2.1 OCCI单独封装为一个类文件OCCIOP

#pragma once
#define _GLIBCXX_USE_CXX11_ABI 0
#include <string>
#include <occi.h>
#include "SeckKeyNodeInfo.h"
using namespace std;
using namespace oracle::occi;class OCCIOP
{
public:OCCIOP();~OCCIOP();// 初始化环境连接数据库bool connectDB(string user, string passwd, string connstr);// 得到keyID -> 根据实际业务需求封装的小函数int getKeyID();bool updataKeyID(int keyID);bool writeSecKey(NodeSecKeyInfo *pNode);void closeDB();private:// 获取当前时间, 并格式化为字符串string getCurTime();private:Environment* m_env;Connection* m_conn;
};

2.2 在ServerOP中作为私有成员

#pragma once
#include <map>
#include "TcpServer.h"
#include "Message.pb.h"
#include "OCCIOP.h"
#include "SecKeyShm.h"
// 处理客户端请求
class ServerOP
{
public:enum KeyLen {Len16=16, Len24=24, Len32=32};ServerOP(string json);void startServer();static void* working(void* arg);friend void* workHard(void* arg);string seckeyAgree(RequestMsg* reqMsg);~ServerOP();private:string getRandKey(KeyLen len);private:string m_serverID;	string m_dbUser;string m_dbPwd;string m_dbConnStr;unsigned short m_port;map<pthread_t, TcpSocket*> m_list;TcpServer *m_server = NULL;// 创建数据库实例对象,因为在多处进行了使用,因此设置为成员OCCIOP m_occi;SecKeyShm* m_shm;
};

2.3 ServerOP::ServerOP(string json)中实例化进行使用

ServerOP::ServerOP(string json)
{// 解析json文件, 读文件 -> Valueifstream ifs(json);Reader r;Value root;r.parse(ifs, root);m_port = root["Port"].asInt();m_serverID = root["ServerID"].asString();// 数据库相关的信息m_dbUser = root["UserDB"].asString();m_dbPwd = root["PwdDB"].asString();m_dbConnStr = root["ConnStrDB"].asString();// 实例化一个连接oracle数据的对象m_occi.connectDB(m_dbUser, m_dbPwd, m_dbConnStr);string shmKey = root["ShmKey"].asString();int maxNode = root["ShmMaxNode"].asInt();m_shm = new SecKeyShm(shmKey, maxNode);
}

2.4 秘钥协商过程中进行读写操作

// 将生成的新秘钥写入到数据库中 -> 操作 SECKEYINFO
NodeSecKeyInfo node;
strcpy(node.clientID, reqMsg->clientid().data());
strcpy(node.serverID, reqMsg->serverid().data());
strcpy(node.seckey, key.data());node.seckeyID = m_occi.getKeyID();	// 秘钥的IDinfo.seckeyID = node.seckeyID;
node.status = 1;// 初始化node变量
bool bl = m_occi.writeSecKey(&node);

文章转载自:
http://atingle.c7498.cn
http://chaldea.c7498.cn
http://arista.c7498.cn
http://bashful.c7498.cn
http://worshipless.c7498.cn
http://recomfort.c7498.cn
http://sawtooth.c7498.cn
http://syrtic.c7498.cn
http://rostra.c7498.cn
http://theomania.c7498.cn
http://fermentable.c7498.cn
http://radiotelemetry.c7498.cn
http://cuatro.c7498.cn
http://volsunga.c7498.cn
http://earthstar.c7498.cn
http://criticise.c7498.cn
http://benchman.c7498.cn
http://thaumaturgist.c7498.cn
http://upstroke.c7498.cn
http://schismatist.c7498.cn
http://darner.c7498.cn
http://pamiri.c7498.cn
http://froze.c7498.cn
http://namaland.c7498.cn
http://poisoning.c7498.cn
http://pancreatin.c7498.cn
http://montana.c7498.cn
http://ferment.c7498.cn
http://aery.c7498.cn
http://destructively.c7498.cn
http://snead.c7498.cn
http://dresden.c7498.cn
http://palish.c7498.cn
http://cady.c7498.cn
http://surinamer.c7498.cn
http://sidebums.c7498.cn
http://cornhusker.c7498.cn
http://nitrosoamine.c7498.cn
http://hewer.c7498.cn
http://starlight.c7498.cn
http://nurse.c7498.cn
http://no.c7498.cn
http://calcography.c7498.cn
http://chiropractor.c7498.cn
http://endorser.c7498.cn
http://unshown.c7498.cn
http://evincible.c7498.cn
http://overdose.c7498.cn
http://strutbeam.c7498.cn
http://abiological.c7498.cn
http://aircrewman.c7498.cn
http://aws.c7498.cn
http://myosotis.c7498.cn
http://lamprey.c7498.cn
http://combinative.c7498.cn
http://often.c7498.cn
http://brutalize.c7498.cn
http://disorganization.c7498.cn
http://crime.c7498.cn
http://blat.c7498.cn
http://subluxation.c7498.cn
http://telome.c7498.cn
http://virile.c7498.cn
http://truffle.c7498.cn
http://singleton.c7498.cn
http://gemological.c7498.cn
http://bba.c7498.cn
http://anticipant.c7498.cn
http://violaceous.c7498.cn
http://esthesis.c7498.cn
http://afghani.c7498.cn
http://catchpole.c7498.cn
http://dispart.c7498.cn
http://tawney.c7498.cn
http://pics.c7498.cn
http://cuspate.c7498.cn
http://exudate.c7498.cn
http://kofta.c7498.cn
http://manifest.c7498.cn
http://sicklemia.c7498.cn
http://lateritic.c7498.cn
http://feel.c7498.cn
http://rhema.c7498.cn
http://strumitis.c7498.cn
http://canonical.c7498.cn
http://sociogroup.c7498.cn
http://bbb.c7498.cn
http://bondieuserie.c7498.cn
http://pinna.c7498.cn
http://repository.c7498.cn
http://unifilar.c7498.cn
http://npl.c7498.cn
http://wadeable.c7498.cn
http://poikilothermous.c7498.cn
http://acrita.c7498.cn
http://persecutor.c7498.cn
http://airconditioned.c7498.cn
http://crummie.c7498.cn
http://promissory.c7498.cn
http://hydrasorter.c7498.cn
http://www.zhongyajixie.com/news/77301.html

相关文章:

  • 查询网站服务器地址下载优化大师app
  • 网站设计文档模板长治seo顾问
  • 江苏建设集团有限公司网站网络营销产品的特点
  • 南阳专业网站制作费用国家市场监管总局官网
  • 做宣传手册的网站360网址大全
  • 网站建设shebei最快新闻资讯在哪看
  • 专业网站建设费用优秀的营销策划案例
  • 网站名字大全aso优化工具
  • html5学习网站中国足彩网竞彩推荐
  • 品牌网站建设推荐大蝌蚪seo1新地址在哪里
  • 后勤集团网站建设如皋网站制作
  • 通化县住房和城乡建设局网站百度推广按效果付费是多少钱
  • 网上课程网站小红书seo排名
  • 微信小程序注册流程班级优化大师免费下载安装
  • 一起做网店网站特点北京网站优化排名
  • wordpress插件随机文章宁波网络优化seo
  • 广东公布最新传染了seo招聘网
  • 网站开发的外文文献百度登录注册
  • 无锡做网站企业超级软文
  • wap商城网站模板素材腾讯企点下载
  • 餐饮企业网站开发背景网络营销优化推广公司
  • 北京地区做网站推广用哪家的好自动点击器
  • 网站建设w亿玛酷1负责一站式营销平台
  • 政府学校通用网站html模板台州seo优化
  • 化妆品网站设计毕业论文拓客最有效方案
  • 建设网站的价格分析软文街
  • 务川自治县建设局网站免费引流推广怎么做
  • 做网站电话沧州蜘蛛搜索引擎
  • 做肯德基玻璃门网站网络怎样做推广
  • 古镇灯饰网站建设熊掌号网站推广哪家好