您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

Eclipse3.0+Myeclipse3.8.1GA+MYSQL开发hibernate

http://www.rdxx.com 04年11月16日 12:12 Blog 我要投稿

关键词: MySQL , MyEclipse , Hibernate , Eclipse3.0 , 开发 , SQL , IP , NAT

import net.sf.hibernate.Session;

import src.PersonSessionFactory;
import src.Person;
/**
 * @author 杨强
 *
 */
public class Queryhib {
 public Iterator getPerson()
 {
  /*
   * Use the ConnectionFactory to retrieve an open
   * Hibernate Session.
   *
   */
  Session session = null;

  try
  {
   session = PersonSessionFactory.currentSession();
   /*
   * Build HQL (Hibernate Query Language) query to retrieve a list
   * of all the items currently stored by Hibernate.
    */
   Query query =
    session.createQuery(
     "select person from Person person ");
   return query.iterate();

  }
  catch (HibernateException e)
  {
   System.err.println("Hibernate Exception" + e.getMessage());
   throw new RuntimeException(e);
  }
  /*
   * Regardless of whether the above processing resulted in an Exception
   * or proceeded normally, we want to close the Hibernate session.  When
   * closing the session, we must allow for the possibility of a Hibernate
   * Exception.
   *
   */
  
 }
 public static void main(String[] args) throws Exception{
  try{
  Queryhib q=new Queryhib(); 
  Iterator it=q.getPerson();
  while(it.hasNext())
  {
  Person temp=(Person)it.next();
  System.out.println(temp.getId());
  System.out.println(temp.getName());
  System.out.println(temp.getAddress());
  }
  }
 catch (Exception ex)
 {
  System.err.println("Hibernate Exception" + ex.getMessage());
  throw new RuntimeException(ex);
 }
 
  }

}
  6.运行Insert.java对数据库进行插入操作;
  7.运行Queryhib对数据库数据进行查询;

      后注:是不是运行时会出现问题,那是因为没有配置log4j,可以将Hibernate下的log4j.properties放入该工程中一切OK了!没有贴图,请大家见谅!

共2页  1 2


 
 
标签: MySQL , MyEclipse , Hibernate , Eclipse3.0 , 开发 , SQL , IP , NAT 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站