utilfavorite.java

来自「spring+struts+hibernate做的银行系统」· Java 代码 · 共 144 行

JAVA
144
字号
 /*
 * Created on 2006-4-14
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.com.tym.util.tablebean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;


import cn.com.tym.pub.DB;
import cn.com.tym.pub.PageBean;
import cn.com.tym.table.bean.ArticleBean;

import cn.com.tym.util.text.ExchangeInput;

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

	
		//���һ�����ѵ��ղ���
	
	   public boolean insert(String favoriteArticleId,String FavoriteVipId,DB db)
	    throws SQLException
	{
	    boolean check = false;
 
	   String strSql = "insert into mdh_favorite values( '"+favoriteArticleId+"','"+FavoriteVipId+"') ";
	      try{
	        if(db.ExecSql(strSql)!= 0)
	            check = true;
 
	      }catch(SQLException e){
	      	 e.printStackTrace();
	      	  throw e;
	      }
	 
	   
	    return check;
	}
	   
	   public  boolean isDel(String favoriteArticleId,String FavoriteVipId,DB db)throws SQLException{
	   	
	   		boolean check=false;
	   		
	   		String strSql="delete  from mdh_favorite  where   favoriteArticleId=" +
	   				"'"+favoriteArticleId+"' and FavoriteVipId='"+FavoriteVipId+"' ";
	   		try{
	   		if(db.ExecSql(strSql)==1){
	   			check=true;
	   		}}catch(SQLException e){
	   			e.printStackTrace();
	   			throw e;
	   		}
	   		return check;
	   }
	   //�ж��������Ƿ������
 public boolean checkArticleId(String favoriteArticleId,String FavoriteVipId,DB db)throws SQLException{
	   	boolean check = false;
	   
	    String strSql = "select favorite_id from mdh_favorite  " +
	    		"where  " +
	    		" favoriteArticleId='"+favoriteArticleId+"'  and favoriteVipid='"+FavoriteVipId+"'";
	      try{
	      	ResultSet rs=db.OpenSql(strSql);
	        if(!rs.next())
	            check = true;   
	      }catch(SQLException e){
	      	e.printStackTrace();
	      	  throw e;
	      }
	   	return check;
	   }
	   
		  //�����ҵ��ղ��б�ҳ��
	   
	  	    public ArrayList getFavoriteList(HttpServletRequest request, DB db,int id)throws SQLException{
	  	        ArrayList list = new ArrayList();
	  	      ArticleBean bean=null;  // ����
	  	   	 	String strSql= "select * from mdh_article where article_id in" +
	  	   	 			" ( select favoriteArticleId from mdh_favorite where favoriteVipid='"+id+"' ) order by article_id desc"; 

	  		Collection arraylist=new ArrayList();
	  			 	ResultSet rs = null;
	  		PageBean pageBean=new PageBean(request);
	  		pageBean.setPageSize(10);
	  		pageBean.count(); 
	  		int currRow=pageBean.getCurrentRow();
	  		int lastRow=pageBean.getLastRow();
 
	  		String csql="select count(*) from mdh_article where article_id in (" +
	  				" select favoriteArticleId from mdh_favorite where favoriteVipid='"+id+"' ) ";
	  		String urlStr="FavoriteAction.do?method=favoriteList&mmId="+id+"";
	  		try{
	  		pageBean.count(db,rs,csql,urlStr);
	  		}
	  		catch(Exception e){}
	  		//strSql="SELECT COUNT(*) FROM  mdh_secondCote WHERE rownum<="+ lastRow;
	  		//strSql="select  count(*)  top '"+lastRow+"' from mdh_secondCote";
	  		
	  		//  strSql="Select top 5 * FROM  (" +strSql + ")";
	  		UtilCote util=new UtilCote();
	  		strSql=" select  top "+lastRow+" *  from mdh_article where article_id in" +
	  				" ( select favoriteArticleId from mdh_favorite where favoriteVipid='"+id+"') order by article_id desc";
	  		try{
	  		rs=db.OpenSql(strSql);
	  		if(currRow>0)
	  			rs.absolute(currRow);
	  	       while(rs.next())
	  	        {  
		              bean=new ArticleBean();
		          	bean.setArticleId(rs.getString("article_id"));
		           	bean.setCoteId(rs.getString("coteId")) ;
	              bean.setCoteName(util.getCoteName(2,db));
	             bean.setMainTitle(rs.getString("mainTitle"));
	             if(bean.getMainTitle().length()>19)//��������19��ʱ,����ʾ������
	             	 bean.setMainTitle(rs.getString("subTitle"));  	
	             bean.setArticleTime(ExchangeInput.getTime(rs.getString("articleTime")));
	             bean.setContent(rs.getString("content"));
	  	             list.add( bean);
	  	             bean=null;
	  	        }}
	  		     	catch(SQLException e){
	  		     		db.close();
	  		       	e.printStackTrace();
	  		     	}
	  		      finally{
	  		      	db.close();
	  		      }
	  				return list;
	  	}
}

⌨️ 快捷键说明

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