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

📄 persondaoimpl.java

📁 一款仿msdn聊天程序,用java编写,很好用!
💻 JAVA
字号:
package cn.mldn.lxh.impl ;
import java.sql.* ;
import java.util.* ;
import cn.mldn.lxh.dbc.* ;
import cn.mldn.lxh.vo.* ;
import cn.mldn.lxh.dao.* ;

public class PersonDAOImpl implements PersonDAO
{
	private DataBaseConnection dbc = null ;
	public PersonDAOImpl()
	{
		this.dbc = new DataBaseConnection() ;
	}
	public int getAllCount() throws Exception
	{
		int count = 0 ;
		String sql = "SELECT COUNT(id) from person" ;
		PreparedStatement pstmt = null ;
		try
		{
			pstmt = this.dbc.getConnection().prepareStatement(sql) ;
			ResultSet rs = pstmt.executeQuery() ;
			if(rs.next())
			{
				count = rs.getInt(1) ;
			}
			pstmt.close() ;
			rs.close() ;
		}
		catch (Exception e)
		{
			throw e ;
		}
		return count ;
	}

	public int getByLikeCount(String cond) throws Exception
	{
		int count = 0 ;
		String sql = "SELECT COUNT(id) from person WHERE uid LIKE ? OR name LIKE ?" ;
		PreparedStatement pstmt = null ;
		try
		{
			pstmt = this.dbc.getConnection().prepareStatement(sql) ;
			pstmt.setString(1,"%"+cond+"%") ;
			pstmt.setString(2,"%"+cond+"%") ;
			ResultSet rs = pstmt.executeQuery() ;
			if(rs.next())
			{
				count = rs.getInt(1) ;
			}
			pstmt.close() ;
			rs.close() ;
		}
		catch (Exception e)
		{
			throw e ;
		}
		return count ;
	}

	public List queryAll(int currentPage,int lineSize) throws Exception
	{
		List<Person> all = new ArrayList<Person>() ;
		String sql = "SELECT id,uid,name,password FROM person limit "+(currentPage-1)*lineSize+","+lineSize ;
		PreparedStatement pstmt = null ;
		try
		{
			pstmt = this.dbc.getConnection().prepareStatement(sql)  ;
			ResultSet rs = pstmt.executeQuery() ;
			while(rs.next())
			{
				Person p = new Person() ;
				p.setId(rs.getInt(1)) ;
				p.setUid(rs.getString(2)) ;
				p.setName(rs.getString(3)) ;
				p.setPassword(rs.getString(4)) ;
				all.add(p) ;
			}
			rs.close() ;
			pstmt.close() ;
		}
		catch (Exception e)
		{
			throw e ;
		}
		finally
		{
			this.dbc.close() ;
		}
		return all ;
	}

	public List queryByLike(String cond,int currentPage,int lineSize) throws Exception
	{
		List<Person> all = new ArrayList<Person>() ;
		String sql = "SELECT id,uid,name,password FROM person WHERE uid LIKE ? OR name LIKE ? limit "+(currentPage-1)*lineSize+","+lineSize ;
		PreparedStatement pstmt = null ;
		try
		{
			pstmt = this.dbc.getConnection().prepareStatement(sql)  ;
			pstmt.setString(1,"%"+cond+"%") ;
			pstmt.setString(2,"%"+cond+"%") ;
			ResultSet rs = pstmt.executeQuery() ;
			while(rs.next())
			{
				Person p = new Person() ;
				p.setId(rs.getInt(1)) ;
				p.setUid(rs.getString(2)) ;
				p.setName(rs.getString(3)) ;
				p.setPassword(rs.getString(4)) ;
				all.add(p) ;
			}
			rs.close() ;
			pstmt.close() ;
		}
		catch (Exception e)
		{
			throw e ;
		}
		finally
		{
			this.dbc.close() ;
		}
		return all ;
	}
};

⌨️ 快捷键说明

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