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

📄 frienddaoimpl.java

📁 通过Tomcat实现服务器的功能然后进行实现 这是一个个人通讯管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */
	public Friend[] findByGroup1(String groupid) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE groupid = ?", new Object[] { groupid } );
	}

	/** 
	 * 返回所有的记录,满足条件 'xmjp = :xmjp'.
	 */
	public Friend[] findWhereXmjpEquals(String xmjp) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE xmjp = ? ORDER BY xmjp", new Object[] { xmjp } );
	}

	/** 
	 * 返回所有的记录,满足条件 'groupid = :groupid'.
	 */
	public Friend[] findWhereGroupidEquals(String groupid) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE groupid = ? ORDER BY groupid", new Object[] { groupid } );
	}

	/** 
	 * 返回所有的记录,满足条件 'name = :name'.
	 */
	public Friend[] findWhereNameEquals(String name) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE name = ? ORDER BY name", new Object[] { name } );
	}

	/** 
	 * 返回所有的记录,满足条件 'age = :age'.
	 */
	public Friend[] findWhereAgeEquals(String age) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE age = ? ORDER BY age", new Object[] { age } );
	}

	/** 
	 * 返回所有的记录,满足条件 'sex = :sex'.
	 */
	public Friend[] findWhereSexEquals(String sex) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE sex = ? ORDER BY sex", new Object[] { sex } );
	}

	/** 
	 * 返回所有的记录,满足条件 'Professional = :professional'.
	 */
	public Friend[] findWhereProfessionalEquals(String professional) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE Professional = ? ORDER BY Professional", new Object[] { professional } );
	}

	/** 
	 * 返回所有的记录,满足条件 'Scholarship = :scholarship'.
	 */
	public Friend[] findWhereScholarshipEquals(String scholarship) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE Scholarship = ? ORDER BY Scholarship", new Object[] { scholarship } );
	}

	/** 
	 * 返回所有的记录,满足条件 'address = :address'.
	 */
	public Friend[] findWhereAddressEquals(String address) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE address = ? ORDER BY address", new Object[] { address } );
	}

	/** 
	 * 返回所有的记录,满足条件 'email = :email'.
	 */
	public Friend[] findWhereEmailEquals(String email) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE email = ? ORDER BY email", new Object[] { email } );
	}

	/** 
	 * 返回所有的记录,满足条件 'phone = :phone'.
	 */
	public Friend[] findWherePhoneEquals(String phone) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE phone = ? ORDER BY phone", new Object[] { phone } );
	}

	/** 
	 * 返回所有的记录,满足条件 'note = :note'.
	 */
	public Friend[] findWhereNoteEquals(String note) throws FriendDaoException
	{
		return findByDynamicSelect( SQL_SELECT + " WHERE note = ? ORDER BY note", new Object[] { note } );
	}

	/**
	 * Method 'FriendDaoImpl'
	 * 
	 */
	public FriendDaoImpl()
	{
	}

	/**
	 * Method 'FriendDaoImpl'
	 * 
	 * @param userConn
	 */
	public FriendDaoImpl( java.sql.Connection userConn)
	{
		this.userConn = userConn;
	}

	/** 
	 * 设置 maxRows
	 */
	public void setMaxRows(int maxRows)
	{
		this.maxRows = maxRows;
	}

	/** 
	 * 获得 maxRows
	 */
	public int getMaxRows()
	{
		return maxRows;
	}

	/**
	 * Method 'getTableName'
	 * 
	 * @return String
	 */
	public String getTableName()
	{
		return "friend";
	}

	/** 
	 * 从结果集中获得单行
	 */
	protected Friend fetchSingleResult(ResultSet rs) throws SQLException
	{
		if (rs.next()) {
			Friend dto = new Friend();
			populateDto( dto, rs);
			return dto;
		} else {
			return null;
		}
		
	}

	/** 
	 * 从结果集中获得多行
	 */
	protected Friend[] fetchMultiResults(ResultSet rs) throws SQLException
	{
		Collection resultList = new ArrayList();
		while (rs.next()) {
			Friend dto = new Friend();
			populateDto( dto, rs);
			resultList.add( dto );
		}
		
		Friend ret[] = new Friend[ resultList.size() ];
		resultList.toArray( ret );
		return ret;
	}

	/** 
	 * 将结果集中的数据复制给DTO
	 */
	protected void populateDto(Friend dto, ResultSet rs) throws SQLException
	{
		dto.setXmjp( rs.getString( COLUMN_XMJP ) );
		dto.setGroupid( rs.getString( COLUMN_GROUPID ) );
		dto.setName( rs.getString( COLUMN_NAME ) );
		dto.setAge( rs.getString( COLUMN_AGE ) );
		dto.setSex( rs.getString( COLUMN_SEX ) );
		dto.setProfessional( rs.getString( COLUMN_PROFESSIONAL ) );
		dto.setScholarship( rs.getString( COLUMN_SCHOLARSHIP ) );
		dto.setAddress( rs.getString( COLUMN_ADDRESS ) );
		dto.setEmail( rs.getString( COLUMN_EMAIL ) );
		dto.setPhone( rs.getString( COLUMN_PHONE ) );
		dto.setNote( rs.getString( COLUMN_NOTE ) );
	}

	/** 
	 * 根据特定的SQL语句返回所有满足条件的好友记录
	 */
	public Friend[] findByDynamicSelect(String sql, Object[] sqlParams) throws FriendDaoException
	{
		//声明参数
		 boolean isConnSupplied = (userConn != null);
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		try {
			// 获得用户指定的connection 或者从ResourceManager获得连接
			conn = isConnSupplied ? userConn : ResourceManager.getConnection();
		
			// construct the SQL statement
			 String SQL = sql;
		
		
			if (logger.isDebugEnabled()) {
				logger.debug( "Executing " + SQL);
			}
		
			//准备 statement
			stmt = conn.prepareStatement( SQL );
			stmt.setMaxRows( maxRows );
		
			//绑定参数
			for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
				stmt.setObject( i+1, sqlParams[i] );
			}
		
		
			rs = stmt.executeQuery();
		
			//获得结果
			return fetchMultiResults(rs);
		}
		catch (SQLException _e) {
			logger.error( "SQLException: " + _e.getMessage(), _e );
			throw new FriendDaoException( "SQLException: " + _e.getMessage(), _e );
		}
		catch (Exception _e) {
			logger.error( "Exception: " + _e.getMessage(), _e );
			throw new FriendDaoException( "Exception: " + _e.getMessage(), _e );
		}
		finally {
			ResourceManager.close(rs);
			ResourceManager.close(stmt);
			if (!isConnSupplied) {
				ResourceManager.close(conn);
			}
		
		}
		
	}

	/** 
	 * 根据特定的SQL语句返回所有满足条件的好友记录
	 */
	public Friend[] findByDynamicWhere(String sql, Object[] sqlParams) throws FriendDaoException
	{
		//声明参数
		 boolean isConnSupplied = (userConn != null);
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		try {
			// 获得用户指定的connection 或者从ResourceManager获得连接
			conn = isConnSupplied ? userConn : ResourceManager.getConnection();
		
			// construct the SQL statement
			 String SQL = SQL_SELECT + " WHERE " + sql;
		
		
			if (logger.isDebugEnabled()) {
				logger.debug( "Executing " + SQL);
			}
		
			//准备 statement
			stmt = conn.prepareStatement( SQL );
			stmt.setMaxRows( maxRows );
		
			//绑定参数
			for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
				stmt.setObject( i+1, sqlParams[i] );
			}
		
		
			rs = stmt.executeQuery();
		
			//获得结果
			return fetchMultiResults(rs);
		}
		catch (SQLException _e) {
			logger.error( "SQLException: " + _e.getMessage(), _e );
			throw new FriendDaoException( "SQLException: " + _e.getMessage(), _e );
		}
		catch (Exception _e) {
			logger.error( "Exception: " + _e.getMessage(), _e );
			throw new FriendDaoException( "Exception: " + _e.getMessage(), _e );
		}
		finally {
			ResourceManager.close(rs);
			ResourceManager.close(stmt);
			if (!isConnSupplied) {
				ResourceManager.close(conn);
			}
		
		}
		
	}

}

⌨️ 快捷键说明

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