⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pooldao.java

📁 这是本人以前在学校时
💻 JAVA
字号:
/*
 * Created on 2006-6-28
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.funddeal.base;

import java.util.List;


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;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PoolDAO {

	public Session createSession() throws HibernateException{
		Configuration cfg=new Configuration().configure();
		SessionFactory sessionFactory=cfg.buildSessionFactory();
		Session session=sessionFactory.openSession();
		return session;
	}
	
	/* 查询是否存在 */
	public boolean select(String sr) throws HibernateException{
		Session session=this.createSession();
		Query query=session.createQuery(sr);
		List list=query.list();
		if(list.size()>0)
			return true;
		else
			return false;
	}
	
	/* Add 添加方法*/
	public String add(Object object) throws HibernateException{
		Session session=this.createSession();
		Transaction tx=session.beginTransaction();
		String id=(String) session.save(object);
		tx.commit();
		session.close();
		return id;
	}
	
	/*查询一条信息*/
	public List exit(String fund) throws HibernateException{
		Session session = this.createSession();
		Query query=null;
		try{
		query=session.createQuery(fund);
		List list=query.list();
		if(list.size()>0){
			return list;
		}
		else
			return null;
		}
		catch(HibernateException e){
			return null;
		}
	}
}

⌨️ 快捷键说明

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