2006年7月21日

          下面是一個用Hibernate實現(xiàn)對數(shù)據(jù)庫進行批量操作的示例

          public class AddMoreWords {

          ?private static String type = "idiom";
          ?/**
          ? * @param args
          ? */
          ?public static void main(String[] args) throws Exception {
          ??// TODO Auto-generated method stub
          ??
          ??Session session = HibernateSessionFactory.currentSession();
          ??Transaction txc = session.beginTransaction();
          ??for(int i=0;i<1000;++i){
          ???WordLib word = new WordLib();
          ???word.setChn("mm"+(i+1));
          ???word.setTime(new Date());
          ???word.setType(type);
          ???session.save(word);
          ???if((i+1)%25 == 0){
          ????session.flush();
          ????session.clear();
          ???}
          ??}
          //??WordLib word = new WordLib();
          //??word.setChn("a");
          //??word.setTime(new Date());
          //??word.setType(type);
          //??session.save(word);
          ??txc.commit();
          ??HibernateSessionFactory.closeSession();
          ??session.flush();
          ??session.close();
          ?}

          }

          posted @ 2006-07-21 15:53 波波 閱讀(373) | 評論 (0)編輯 收藏


          posts - 1, comments - 0, trackbacks - 0, articles - 0

          Copyright © 波波

          主站蜘蛛池模板: 永德县| 玉溪市| 拉萨市| 鄱阳县| 金乡县| 宁乡县| 蛟河市| 新晃| 密云县| 唐河县| 类乌齐县| 娱乐| 偏关县| 广平县| 隆尧县| 宝清县| 葵青区| 乳源| 岑巩县| 云安县| 勃利县| 曲松县| 合作市| 崇仁县| 海兴县| 志丹县| 高安市| 灵台县| 平潭县| 大关县| 丹东市| 湄潭县| 扎鲁特旗| 托里县| 武夷山市| 金堂县| 久治县| 嘉义市| 班玛县| 博湖县| 呼图壁县|