TWiki . Catch0405 . RetrieveDataFromDbKaisersrotsupermix

import java.util.Iterator;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

/*
 * Created on Jan 3, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author denis
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class RetrieveData {
   
   RetrieveData(){
      
      this.select();
   
   }

   void select() {

      try {

         //Create the SessionFactory
         Configuration cfg = new Configuration().addClass(StoreTupel.class);
         SessionFactory factory = cfg.buildSessionFactory();
         //Create the Session
         Session session = factory.openSession();
         //Create the Transaction               
         Transaction tx = session.beginTransaction();
         
         Query query = session               
                 .createQuery("select c from StoreTupel as c where anzahl like :anzahl");

         query.setString("anzahl", "%");
         for (Iterator it = query.iterate(); it.hasNext();) {
            StoreTupel storeTupel = (StoreTupel) it.next();
            System.out.println("searched tupel is: " + storeTupel.getAnzahl());                  
         }

         tx.commit();

      } catch (HibernateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
}

-- OtherDenisRaschpichler - 03 Jan 2005

----- Revision r1.1 - 03 Jan 2005 - 18:45 - OtherDenisRaschpichler
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

This website has been archived and is no longer maintained.