java从mongodb和mysql读ecshop商品信息对比

2013-08-06 18:41 来源:www.chinab4c.com 作者:ecshop专家

     当我们知道ecshop数据库中商品数据太多的时候,是非常麻烦的,这个时候我们必须通过其他手段来处理,我的数据库中产品信息达到了500万条,如果简单的放在mysql数据库里面,肯定不行,这个时候我们就想到了把ecshop商品信息。存入一份到mongodb里面,然后通过java接口来从ecshop mongodb中取得数据,结果比php在mysql中取得ecshop商品信息,速度块一倍多。

  long mmm = System.currentTimeMillis();

MysqlDb x = new MysqlDb("mall","root","123456","172.168.16.23");
PreparedStatement ps = x.prepare("select goods_id,goods_name,cat_id,brand_id,provider_name from ecs_goods limit ?,?");
ps.setString(1,"2100000");
ps.setString(2,"300000");
ResultSet res = ps.executeQuery();
res.next();
System.out.println(res.getString("goods_name"));
System.out.println(System.currentTimeMillis()-mmm);
 
long mmm = System.currentTimeMillis();
Mongodb mg = new Mongodb("dbname","system","system","127.0.0.1");
DB      db = mg.selectDB("test");
DBCollection goods = db.getCollection("goods");
 
System.out.println(System.currentTimeMillis()-mmm);
while(res.next()) {
//System.out.println(res.getString("goods_name"));
BasicDBObject row = new BasicDBObject();
row.put("goods_id",res.getString("goods_id"));
row.put("goods_name",res.getString("goods_name"));
row.put("cat_id",res.getString("cat_id"));
row.put("brand_id",res.getString("brand_id"));
row.put("provider_name",res.getString("provider_name"));
goods.insert(row);
}

   来源:http://www.chinab4c.com