Hibernate a simple tutorial with MySQL database

Source: Internet
Author: User

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;

}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.