Experience the real struts development (2 period) 4

zhaozj2021-02-17  53

We modify the configuration file hibernate.cfg.xml

PUBLIC "- // Hibernate / Hibernate Configuration DTD // EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

Java: comp / env / jdbc / mysql

false FALSE

Net.sf.hibernate.dialect.mysqldiaAlaforct

Modify Web.xml Add

TestConnectionPooler

com.test.web.testhbmservlet

2

The test servlet is as follows

Package com.test.Web;

Import javax.servlet.servletException;

Import javax.servlet.http.httpservlet;

Import net.sf.hibernate.hibernateException;

Import net.sf.hibelnate.mappingexception;

Import net.sf.hibernate.Session;

Import Net.sf.hibActory;

Import Net.sf.hibiBernate.cfg.configuration;

Import org.apache.log4j.logger;

Import com.yjsoft.hbm.userinfo;

/ **

* @Author yanghx

*

* Change the template for the generated type annotation for the window> Preferences> Java> Code Generation> Code and Notes

* /

Public class testhbmservlet extends httpservlet {

Private static logger log = logger.getlogger;

Public void init () throws servletexception {

Super.init ();

CONFIGURATION CFG = NULL;

SessionFactory sf = NULL;

// SchemaExport Ptemp = NULL;

Session s = null; try {

// cfg = new configuration ();

Cfg = new configuration (). configure ("/ hibernate.cfg.xml);

//cfg.addclass (userinfo.class);

} catch (mappingexception e1) {

E1.PrintStackTrace ();

Log.Error ("Map Error:" E1);

Return;

} catch (hibernateException e) {

// TODO automatically generates a Catch block

E.PrintStackTrace ();

Log.Error ("Map Error:" E);

Return;

}

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

New Post(0)