Create a Hibernate + Struts instance (Animation) using the MyEclipse plugin (animation)

xiaoxiao2021-03-06  15

Create a Hibernate Struts instance using myECLIPSE plugin

Download: http://free3.e-168.cn/oksonic/download/myeclipse_hibernate video .exe

This is my second video tutorial, I hope to bring you a little help.

Preparation: 1. Database, here I choose Mysql2, Eclipse, MyEclipse, here I choose Eclipse3.01 Chinese package, myeclipse 3.843, Tomcat

The configuration of the above tools has been completed

Start launching the MySQL service, create a UserList table, you can use the script in the package.

Here I am already built, you can create scripts in the package

New project, here is Hitt

Create a struts framework

For the use of Struts, please refer to my first video.

Now is a creation of a data connection, you have to carefully. .

JDBC: MySQL: // localhost: 3306 / test

The JDBC package containing MySQL is already included. Extra Class Path: Here is where JDBC package is placed, you can choose.

com.mysql.jdbc.driver

The JDBC package is also available under the Webroot / Lib directory in the project directory.

Ok, the basic configuration work has been completed.

You can now write code.

New Action, you can copy the content in the following accessories, but it will be erroneous after saving, remember importing the class library, and exception handling.

Copy is wrong. . .

It's a bit slow, don't blame. . HibernateUtil class yet

Newly built a type of Hibernateutil should be responsible for calling hibernate related operations. Here I am directly copying the documents from the original project.

The SESSION class library is wrong, mistakes. . .

New JSP file index.jsp

Add a link to the file, call the action directly. This record mistake is much larger, and you have a lot of time. .

Write code

There is also a need to handle the jump in the action.

OK, test. .

If you don't have any errors, you have been successful, you can view it in the database. My machine is really slow, who can be a good machine. what! ! !

Successful.

I wish you a success.

If you have any questions, you can contact me. QQ: 71279650Email: oksonic@sina.com

BYE

/ ===================================== h 附: hibernateutil.java

Import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory;

Import net.sf.hibernate. *; import net.sf.hibernate.cfg. *;

/ ** * @Author administrator * * Todo To change this generated type annotation template, please turn to * Window - Preference - Java - Code - Code Template * / Public Class Hibernateutil {Private Static Log Log = logfactory.getlog (HibernateUtil.class); private static final SessionFactory sessionFactory; static {try {sessionFactory = new Configuration () configure () buildSessionFactory ();..} catch (Throwable ex) {log.error ( "Initial SessionFactory creation failed.", ex); throw new ExceptionInInitializerError (ex);}} public static final ThreadLocal session = new ThreadLocal (); public static Session currentSession () throws HibernateException {Session s = (Session) session.get (); // Open a new Session If this Thread Has None YET IF (S == NULL) {s = sessionFactory.opensesis (); session.set (s);} Return S;} public static void closesession () THROWS HibernateException {session s = (session) Session.get (); session.set (null); if (s! = null) s.close ();}}

-------------------------------------------------- --- Enter data code in action session session = hibernateutil.currentSession (); transaction tx = session.begintransAction (); userlist ulist = new userlist (); ulist.setusername ("sonic"); ulist.setUserPwd "oksonic"); session.save (ulist); tx.commit (); hibernateutil.closesis ();

转载请注明原文地址:https://www.9cbs.com/read-47495.html

New Post(0)