Find a lot of hibernate related tutorials on the internet, most of which are combined with a Web server, write a separate example to run directly under Eclipse, without having to write your own ant script, without having to combine a Web server. But need MySQL database-_-
First learn how to use eclipse, and then download all the jar files hibernate need, and finally install MySQL
Get ready to start!
The first step is to create a table structure as follows
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id| int (11) | no| MUL | null| auto_increment |
| title| VARCHAR (400) | YES | | null| |
| Content | Text | YES | | null| |
| Time | datetime | YES | | null| |
+-----------+--------------+------+-----+---------+----------------+
The second step is to create a Java project in Eclipse (the package name I used in my project is CN.COM.NICK.HBM). Write the News.java class, which corresponds to the table in the database
Package CN.COM.NICK.HBM;
Import java.util.Date;
public class News
{
private int id;
Private String title;
Private String content;
private date date;
public int getId ()
{return
ID;
}
public void setId (int id)
{
this.id = ID;
}
Public String GetTitle ()
{return
title;
}
public void Settitle (String title)
{
this.title = title;
}
Public String getcontent ()
{return
content;
}
public void SetContent (String content)
{
this.content = content;
}
Public date getDate ()
{return
date;
}
public void setdate (date date)
{
this.date = date;
}
}