test.java
来自「struts+hibernate编写的一WEB的例子欢迎大家下载使用」· Java 代码 · 共 37 行
JAVA
37 行
package com.sterning.bean.hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.sterning.books.model.Books;
public class Test {
public static void main(String[] args) {
try {
SessionFactory sf =
new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Books pd = new Books();
pd.setBookId("1");
pd.setBookName("教父");
pd.setBookAuthor("Godfather");
pd.setBookPublish("1");
pd.setBookIsbn("DVD");
session.save(pd);
tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?