最后是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] 下一页
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18