打印本文 打印本文 关闭窗口 关闭窗口
使用Hibernate 连接SQL Server 2000
作者:武汉SEO闵涛  文章来源:敏韬网  点击数5577  更新时间:2007/11/14 13:06:34  文章录入:mintao  责任编辑:mintao
注释,感觉是Hibernate的缺陷。

     最后是Test.java

import net.sf.hibernate.*;

import net.sf.hibernate.cfg.*;

 

 

public class Test {

 

 

    public static void main(String[] args) {

        try {

            SessionFactory sf = new Configuration().configure().buildSessionFactory();

            Session session = sf.openSession();

            Transaction tx = session.beginTransaction();

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

                Customer customer = new Customer();

                customer.setUsername("customer" + i);

                customer.setPassword("customer");

                session.save(customer);

            }

 

 

            tx.commit();

            session.close();

        }

        catch (HibernateException e) {

            e.printStackTrace();

        }

    }

}

 

 

好了,在项目中添加对Hibernate库文件的引用,编译执行,你会在数据库中找到新添加的记录。

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口