tinfodao.java

来自「持久层hibernate技术使用的一个例子」· Java 代码 · 共 119 行

JAVA
119
字号
package cn.hope.front.pojo.dao;

import java.util.List;

import net.sf.hibernate.HibernateException;

import org.apache.log4j.Logger;





import cn.hope.front.pojo.TInfo;



import cn.hope.front.pojo.base.BaseTInfoDAO;


public class TInfoDAO extends BaseTInfoDAO {

	Logger log = Logger.getLogger(TInfoDAO.class.getName());

	
	


	/**
	 * Default constructor.  Can be used in place of getInstance()
	 */
	public TInfoDAO () {}

	/****************wuyongbo************/
	public TInfo searchByKey(String t_id) throws HibernateException {
		List list = null;
		TInfo tInfo = new TInfo();
		String sqlStr = "select tInfo from TInfo tInfo where tInfo.flag='0' and tInfo.TId='"+t_id+"'";
		try {
			initialize();
			list = this.getSession().find(sqlStr);
			if (list.size() > 0) {
				tInfo = (TInfo) list.get(0);
			}
		} 
		catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
		finally {
			closeCurrentThreadSessions();
		}
		return tInfo;
	}
	public void modify(TInfo tInfo) throws HibernateException {
		try {
			initialize();
			this.update(tInfo);
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}

	/****************jinxiaolei************/
	public List searchAll() throws HibernateException {
		List list = null;
		String sqlStr = "select tInfo from TInfo tInfo where tInfo.flag='0' ";
		try {
			initialize();
			list = this.getSession().find(sqlStr);
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
		return list;
	}
	

	//==============zhang hong tao =============================
	
	public TInfo U01DT(String name,String psw) throws HibernateException {
		List list = null;
		TInfo tinfo=null;
		String sqlStr = "from TInfo t where t.flag='0' and t.TId='"+name+"' and t.TPassword='"+psw+"'";
		try {
			initialize();
			//查寻名字		
			list = this.getSession().find(sqlStr);//从数据库提取名字和密码
			System.out.println(list);
			if(list!=null){
				System.out.println("tttttttttttttttttttttttttt");
				if(list.size()>0){	//放到实体中去		
					tinfo =(TInfo) list.get(0);
		}else{
			tinfo=null;
			}
		}
			System.out.println(list);
					return tinfo;
					
		} 
		catch (HibernateException e) {
		log.error(e);
		e.printStackTrace();
		throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}


}

⌨️ 快捷键说明

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