Hibernate
在test01右键新建其他找到hibernate文件夹下的Hibernate Configuration File(cfg.xml)
oracle.jdbc.driver.OracleDriver 123456 jdbc:oracle:thin:@localhost:1521:orcl test0816 TEST0816 org.hibernate.dialect.Oracle10gDialect true true update
package com.hanqi.test;import static org.junit.Assert.*;import org.hibernate.SessionFactory;import org.hibernate.boot.registry.StandardServiceRegistryBuilder;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.junit.Test;public class Test01 { //测试Hibernate连接 @Test public void test() { //1获取配置文件 Configuration cfg=new Configuration().configure(); //2注册配置 ServiceRegistry sr=new StandardServiceRegistryBuilder() .applySettings(cfg.getProperties()).build(); //3获取SessionFactory (相当于jdbc的连接connection) SessionFactory sf=cfg.buildSessionFactory(sr); System.out.println(sf); sf.close(); }}
package com.hanqi.entity;import java.util.Date;//持久化类 实体化类//不需要使用final终态public class User { private int userID; private String userName; private Date birthday; private double money; private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getUserID() { return userID; } public void setUserID(int userID) { this.userID = userID; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } public User(int userID, String userName, Date birthday, double money, String password) { super(); this.userID = userID; this.userName = userName; this.birthday = birthday; this.money = money; this.password = password; } //必须包含无参的构造方法 //因为需要用到反射 反射要求是构造无参实例 public User() { super(); } }
lib下面的.jar文件 点击第一个文件 再按shift 再点最后一个文件就全选了。