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

类别:Java 点击:0 评论:0 推荐:

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);

            }

        }

    }

}

本文地址:http://com.8s8s.com/it/it16701.htm