Friday, October 2, 2009

Toy Story Portable Dvd Player

Part 2

In the previous example we saw how to configure a jsp project Framewor
and Hibernate, but we need to see how to save (insert)
in the database, this process is very simple and we will make
as follows:

in class: consulta_empresa company created a method to keep public String

guardar_empresa (Empresa em) {try {



org.hibernate.Transaction session.beginTransaction tx = ();
Session.save (em);

tx.commit () ;
return "Company saved"

} catch (Exception e) {
e.printStackTrace ();}



return "Error";

}}

the method returns the type that we can leave as
more we accommodate us, but we spent importate an object type that this company
seti its parameters with the set that has
this object already created and that is the representation of the table
database.

consulta_empresa class has the following.

Session session = null;
public
consulta_empresa () {
this.session = NewHibernateUtil.getSessionFactory (). GetCurrentSession ();}

newHibernateUtil
and is the class we created earlier
(to understand it is necessary to see previous article)

this is the code I have in a jsp page to call the method guardar_empresa
.
<% if(request.getParameter("guardar")!=null){ out.println("nombre: "+request.getParameter("nombre")); Empresa e=new Empresa(); e.setNombre(""+request.getParameter("nombre")); e.setDireccion(""+request.getParameter("direccion")); e.setRut(""+request.getParameter("rut")); consulta_empresa co=new consulta_empresa(); String respuesta; respuesta=co.guardar_empresa(e); out.println("br "); out.println("center "+respuesta+" /center"); } %>

As next step is to better understand the language that has
Hibernate HQL.

http://www.java2s.com/Code/Java/Hibernate/CatalogHibernate.htm

http://www.acsinet-solutions.com/es/tutoriales/hibernate/01-mapeo_sencillo.html

Basic Configuration Mapping Single with Spring Framework:

http : / / www.acsinet-solutions.com/es/tutoriales/hibernate/02-mapeo_sencillo.html

0 comments:

Post a Comment