本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9691275
建立时间:2004年12月20日




[数据库]windows下bdb数据库的使用
原创空间,  软件技术,  电脑与网络

邢红瑞 发表于 2007/6/20 9:43:26

  Berkeley DB是由美国Sleepycat Software公司开发的一套开放源码的嵌入式数据库的程序库(database library),它为应用程序提供可伸缩的、高性能的、有事务保护功能的数据管理服务。Berkeley DB为数据的存取和管理提供了一组简洁的函数调用API接口。以下是chinaunix.net上一位高手给出的解释,在这里引用一下。 mysql就是用BDB实现的(mysql的后台) 。mysql快,BDB比mysql还要快N倍。 BDB并发高于RDBMS。 容量支持可达256TB。 基于HASH支持select数据比RDBMS快.数据库巨人Oracle在2006年2月14日宣布已经收购 Sleepycat,并将BerkeleyDB数据库纳入了自己的嵌入式数据库产品线。Mysql在5.1.2版本中已经放弃对bdb引擎的支持,转以插件的形式提供。BDB支持四种不同类型的库格式(BTree、Hash、Queue、Recno),可以根据不同应用需求配置使用不同的库格式,java只支持BTree、Hash,JE只支持BTree,但是已经够用了,书生网当年的缓存使用sqllite做缓存前台,bdb做缓存后台,单台pc使用tomcat支持每日200w的PV。大家可以下载bdb源码,由c写成,在build_windows中有vc的工程文件,使用vc6可以编译通过,对于我的机子要删除X64和AMD的发布版本。编译完成后,生成所有的配置文件和libdb47.lib、libdb47.dll文件,一般不要使用bdb的debug的版本,exe运行时容易出现0xc150002的错.下面给出可以运行的代码,c++的#include "stdafx.h"#include <iostream>#include <db_cxx.h>using std::cout;using std::endl;using std::cerr; int main(int argc, char* argv[]){ try    {        /* 1: create the database handle */        Db db(0, 0);        /* 2: open the database using the handle */  db.open(NULL, "D:\\Oracle\\Berkeley DB 4.7.25\\chap4_db", NULL, DB_BTREE, DB_CREATE, 0644);        /* 3: create the key and value Dbts */        char *first_key = "first_record";        u_int32_t key_len = (u_int32_t)strlen(first_key);        char *first_value = "我们都是装b犯!!";        u_int32_t value_len = (u_int32_t)strlen(first_value);  Dbt key(first_key, key_len + 1 );        Dbt value(first_value, value_len + 1);        /* 4: insert the key-value pair into the database */        int ret;        ret = db.put(0, &key, &value, DB_NOOVERWRITE);  if (ret == DB_KEYEXIST)        {   cout << "hello_world: " << first_key << " already exists in db"<< endl;        }        /* 5: read the value stored earlier in a   Dbt object */        Dbt stored_value;        ret = db.get(0, &key, &stored_value, 0);        /* 6: print the value read from the database */        cout << (char *)stored_value.get_data() << endl;        /* 7: close the database handle */        db.close(0);    }    catch(DbException &dbex)    {        cerr << "hello_world: exception caught: " << dbex.what() << endl;    } return 0;}。本文的思路和代码 没有用于启明星辰的任何产品,包括UTM. 


阅读全文(6273) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144757432 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号