famillydao.java

来自「是一个J2EE的项目,在eclipse下编译通过,应用struts,hibern」· Java 代码 · 共 90 行

JAVA
90
字号
package com.bjjd.DAO;
import java.util.ArrayList;
import com.bjjd.datamodel.Familly;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/*
 * 家庭数据持久层DAO
 * 
 */
public class FamillyDAO {
	//查询家庭记录方法
	public ArrayList searchfamilly(String str)throws Exception{
		ArrayList mainproblems=null;
		Session session=null;
		try
	    {
	    	
	    	SessionFactory factory = new Configuration().configure().buildSessionFactory();
	    	 session =factory.openSession();
	    	mainproblems = (ArrayList)session.createQuery("from Familly where personid ="+str).list();
	    	session.beginTransaction().commit();
	    	return mainproblems;
	    }
	    catch(Exception e)
	    {
	    	throw e;
	    	//return users;
	    }
	    finally
	    {
	    	session.close();
	    }
	}
	//删除家庭记录方法
	public void deletefamilly(Familly mp)throws Exception{
		Session session=null;
		try{
			SessionFactory factory = new Configuration().configure().buildSessionFactory();
            session =factory.openSession();
	    	session.delete(mp);
	    	session.beginTransaction().commit();
		}
		catch(Exception e){
			throw e;
		}
		finally
	    {
	    	session.close();
	    }
	}
	//新建家庭记录方法
	public void createfamilly(Familly mp)throws Exception{
		Session session=null;
		try{
			SessionFactory factory = new Configuration().configure().buildSessionFactory();
            session =factory.openSession();
	    	session.save(mp);
	    	session.beginTransaction().commit();
		}
		catch(Exception e){
			throw e;
		}
		finally
	    {
	    	session.close();
	    }
	}
	//修改家庭记录方法
	public void updatefamilly(Familly mp)throws Exception{
		Session session=null;
		try{
			SessionFactory factory = new Configuration().configure().buildSessionFactory();
            session =factory.openSession();
	    	session.update(mp);
	    	session.beginTransaction().commit();
		}
		catch(Exception e){
			throw e;
		}
		finally
	    {
	    	session.close();
	    }
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?