Hibernate(1):简单配置及运行测试

hibernate的配置步骤:
-导入相关的jar包
下载网站: http://sourceforge.net/projects/hibernate/files/
文件目录:目录
-添加配置文件 hibernate.cfg.xml

<hibernate-configuration>
	<session-factory >
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
		<property name="hibernate.connection.driver_class ">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernateTest</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password"> </property>
		<property name="show_sql">true</property>
		<mapping resource="cn/hrbust/pojo/User.hbm.xml"/>
	</session-factory>
</hibernate-configuration>

-创建user.hdm.xml

<?xml version="1.0"?>
<hibernate-mapping package="com.allwinter.pojo">
    <class name="User" table="t_user">
        <id name="id" column="id">
            <generator class="native"/>
        </id>
        <property name="name" column="name"/>
        <property name="age" column="age"/>
    </class>
</hibernate-mapping>


-创建实体类

package com.zhangyi.po;
 
import java.sql.Date;
 
public class User {
	private int id;
	private String name;
	private String gender;
	int age;
	Date birthday;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	
}

-创建表
在这里插入图片描述
要注意mysql5.0与8.0的不同,以及url的不同写法:
在这里插入图片描述
-idea中连接database
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值