JSP hibernate Getting Started Tutorial 1th/3 page _jsp programming

Source: Internet
Author: User
Tags log4j
For example:
Copy Code code as follows:

Hibernatetest.java
Import onlyfun.caterpillar.*;
Import net.sf.hibernate.*;
Import net.sf.hibernate.cfg.*;
Import java.util.*;
public class Hibernatetest {
public static void Main (string[] args) throws Hibernateexception {
Sessionfactory sessionfactory = new Configuration (). Configure (). Buildsessionfactory ();
Session session = Sessionfactory.opensession ();
List users = Session.find ("from User");
User updated = null;
for (Listiterator iterator = Users.listiterator (); Iterator.hasnext ();) {
User user = (user) iterator.next ();
if (updated = null)
Updated = user;
System.out.println (User.getname () +
"\n\tage:" + user.getage () +
"\n\tsex:" + user.getsex ());
}
Updated.setname ("Justin");
Session.flush ();
Users = Session.find ("from User");
Session.close ();
Sessionfactory.close ();
for (Listiterator iterator = Users.listiterator (); Iterator.hasnext ();) {
User user = (user) iterator.next ();
System.out.println (User.getname () +
"\n\tage:" + user.getage () +
"\n\tsex:" + user.getsex ());
}
}
}

This program displays all the data in the datasheet, updates the first data in the datasheet, and executes the following results:
Log4j:warn No Appenders could is found for logger (net.sf.hibernate.cfg.Environment).
Log4j:warn Please initialize the log4j system properly.
Hibernate:select user0_.user_id as user_id, user0_.name as name, user0_.sex as sex, user0_.age as age from user user0_
Caterpillar
Age:28
Sex:m
Momor
Age:25
Sex:f
Bush
Age:25
Sex:m
Becky
Age:35
Sex:f
Hibernate:update USER set name=?, sex=?, age=? where user_id=?
Hibernate:select user0_.user_id as user_id, user0_.name as name, user0_.sex as sex, user0_.age as age from user user0_
Justin
Age:28
Sex:m
Momor
Age:25
Sex:f
Bush
Age:25
Sex:m
Becky
Age:35
Sex:f
Current 1/3 page 123 Next read the full text
Related Article

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.