CSDN博客

img yanghx2000

体会真正的Struts开发(2期)5

发表于2004/3/21 17:50:00  614人阅读

try {

            //pTemp = new SchemaExport(cfg);

            //pTemp.create(true, true);

            sf = cfg.buildSessionFactory();

            s = sf.openSession();

        } catch (HibernateException e) {

            e.printStackTrace();

            log.error("Hibernate 错误" + e);

            return;

        }

        try {

            log.info("Open Session OK");

           

            long start = System.currentTimeMillis();

            for (int i = 0; i < 10; i++) {

                UserInfo message = new UserInfo();

                message.setId(String.valueOf(i));

                message.setUserName(String.valueOf(i));

                message.setPassword(String.valueOf(i));

                try {

                    s.save(message);

                    s.flush();

                    //s.evict(message);

                } catch (HibernateException e4) {

                    e4.printStackTrace();

                    log.error("Hibernate Insert 错误" + e4);

                    return;

                }

            }

            long end = System.currentTimeMillis();

            log.info(new Long(end - start));

        }

        catch(Exception e){

            e.printStackTrace();

            log.error("Hibernate Insert 错误" + e);

            return;

        }

        finally {

            try {

                s.close();

            } catch (HibernateException e4) {

                e4.printStackTrace();

                log.error("Hibernate Close 错误" + e4);

            }

        }

    }

}

0 0

相关博文

我的热门文章

img
取 消
img