置頂隨筆

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

          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 波波 閱讀(374) | 評(píng)論 (0)編輯 收藏


          2006年7月21日

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

          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 波波 閱讀(374) | 評(píng)論 (0)編輯 收藏


          僅列出標(biāo)題  

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

          Copyright © 波波

          主站蜘蛛池模板: 西乡县| 盐津县| 修水县| 岑巩县| 手游| 桓台县| 清流县| 项城市| 红原县| 甘德县| 天峻县| 宣武区| 乌兰浩特市| 乌鲁木齐市| 望城县| 芜湖县| 抚顺市| 改则县| 灵山县| 建平县| 阿勒泰市| 安多县| 临泉县| 金秀| 灵山县| 乌鲁木齐县| 安塞县| 陵川县| 广安市| 新宾| 昌邑市| 会理县| 绥滨县| 耒阳市| 乃东县| 嵩明县| 夹江县| 晴隆县| 武宣县| 随州市| 垦利县|