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

📄 mainbean.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			return null;
		}
		sql = "select ID,TITLE,FROMSITE,AUTHOR,ADDTIME,EDITTIME,TIMES,ORGID,IMG,FTPFILE,OLDORGID from article where ID = "+id+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		if (rs.next())
		{
			for(int i=1;i<=cols;i++)
			{
				String field = ds.toString(rsmd.getColumnName(i));
				String value = ds.toString(rs.getString(i));
				hash.put(field,value);
			}
		}
		}catch(Exception e){System.out.println("MainBean.getOneNews(String id)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getOneNews(String id)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getOneNews(String id)关闭声明时statement出错"+e);}		
		}
		return hash;
	}


	//根据某文章ID取得文章正文----------------------------------------------------------------------
	public String getOneContent(String id)
	{
		String strcontent = "";
		strcontent = QueryBLOB_JNDI("ARTICLE","ID="+id,"CONTENT");
		return strcontent;
	}


	//取得某文章的相关评论信息--------------------------------------------------------------------------
	public Vector getRelateCom(String id)
	{		
		Vector vect = new Vector();
		String sql ="";
		sql = "select * from COMMENTB where ARTICLEID = "+id+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		//取得列数和列名
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		while(rs.next())
		{	
			Hashtable hash = new Hashtable();
			for(int i=1;i<=cols;i++)
			{
				String field = ds.toString(rsmd.getColumnName(i));
				String value = ds.toString(rs.getString(i));
				hash.put(field,value);
			}
			vect.add(hash);
		}
		}catch(Exception e){System.out.println("MainBean.getRelateCom(String id)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getRelateCom(String id)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getRelateCom(String id)关闭声明时statement出错"+e);}		
		}
		return vect;
	}

	//取得某文章的相关评论信息--------------------------------------------------------------------------
	public Vector getRelateArticle(String id)
	{		
		Vector vect = new Vector();
		String sql ="";
		String keyword = toName("ARTICLE","ID","KEYWORD",id+"");
		sql = "select ID,TITLE,ADDTIME,HITS from ARTICLE where ifshow='1' and ORGANID='00000000000000000000' and ID!="+id+" and (TITLE like '%"+keyword+"%' or KEYWORD like '%"+keyword+"%')";
		ResultSet rs = selectRecord(sql);

		//取得列数和列名
		Statement stmt = null;
		try{
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		while(rs.next())
		{	
			Hashtable hash = new Hashtable();
			hash.put("ID",ds.toString(rs.getString("ID")));
			hash.put("TITLE",ds.toString(rs.getString("TITLE")));
			hash.put("ADDTIME",ds.toString(rs.getString("ADDTIME")));
			hash.put("HITS",ds.toString(rs.getString("HITS")));
			vect.add(hash);
		}
		}catch(Exception e){System.out.println("MainBean.getRelateArticle(String id)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getRelateArticle(String id)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getRelateArticle(String id)关闭声明时statement出错"+e);}		
		}
		return vect;
	}


	//取得某一个版面下的文章------------------------------------------------------------
	public Vector getArc(String menuid,String whichtable)
	{
		Vector vect = new Vector();
		String sql = "";
		sql = "select ID,TITLE,ADDTIME,HITS from ARTICLE where MENUID = "+menuid+" and  IFSHOW = '1' and WHICHTABLE = '"+whichtable+"' and ORGANID='00000000000000000000'  order by edittime desc";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		//取得列数和列名
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		while(rs.next())
		{	
			Hashtable hash = new Hashtable();
			for(int i=1;i<=cols;i++)
			{
				String field = ds.toString(rsmd.getColumnName(i));
				String value = ds.toString(rs.getString(i));
				hash.put(field,value);
			}
			vect.add(hash);
		}
		}catch(Exception e){System.out.println("MainBean.getArc(String,String)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getArc(String,String)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getArc(String,String)关闭声明时statement出错"+e);}		
		}
		return vect;
	}


	//分页取得某一个版面下的文章------------------------------------------------------------
	public Vector getArc(String menuid,String whichtable,int page,int records)
	{
		Vector vect = new Vector();
		String sql = "";
		sql = "select ID,TITLE,ADDTIME,HITS from ARTICLE where MENUID = "+menuid+" and   IFSHOW ='1'  and WHICHTABLE = '"+whichtable+"' and ORGANID='00000000000000000000'  order by edittime desc";
		return db.getOnePage(sql,page,records,false);
	}

	
	//取得二级以下菜单的名称--------------------------------------------------------------
	public String getMenuName(String menuid,String which)
	{
		String sql = "";
		String menu = "";
		if(which.equals("0")) sql = "select MENUCHILD as MENUNAME from menuchild where id = "+menuid+"";
		else sql = "select MENU3 as MENUNAME from menu where id = "+menuid+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			menu = ds.toString(rs.getString("MENUNAME"));
		}
		}catch(Exception e){System.out.println("MainBean.getMenuName(String menuid,String which)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getMenuName(String menuid,String which)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getMenuName(String menuid,String which)关闭声明时statement出错"+e);}		
		}
		return menu;
	}

	//取得所有栏目精选------------------------------------------------------------------------
	public Vector getGood()
	{
		Vector vect = new Vector();
		String sql = "";

		sql = " select ID,TITLE,ADDTIME,HITS from ARTICLE where IFGOOD='1' and IFSHOW='1' order by edittime desc";
		ResultSet rs = selectRecord(sql);

		Statement stmt = null;
		try{
		//取得列数和列名
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		while(rs.next())
		{	
			Hashtable hash = new Hashtable();
			for(int i=1;i<=cols;i++)
			{
				String field = ds.toString(rsmd.getColumnName(i));
				String value = ds.toString(rs.getString(i));
				hash.put(field,value);
			}
			vect.add(hash);
		}
		}catch(Exception e){System.out.println("MainBean.getGood()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getGood()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood()关闭声明时statement出错"+e);}		
		}
		return vect;
	}

	//取得某一级版面下的焦点------------------------------------------------------------------------
	public Vector getGood(String id)
	{
		Vector v_article = new Vector();
		
		//取得显示数量
		int num = getNUMfromMAINTABLE( id);
		String sql = ""; 
		ResultSet rs = null;

		//检索菜单表编号
		sql = getStrIDfromMENUTABLE( id , "" );
		if(sql.equals("")) return v_article;

		sql = "select id from article where whichtable='1' and ifshow='1' and ifgood ='1' and ORGANID='00000000000000000000' and menuid in ("+sql+")";
		sql = "select id,title,addtime,hits from article where id in ("+sql+") order by edittime desc";
		
		try
		{
			rs = selectRecord(sql);
			int i = 0;
			int count = 0 ;
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = 0;
			cols = rsmd.getColumnCount();				
			while(rs.next())
			{
				Hashtable hash = new Hashtable();
				for(i=1;i<=cols;i++)
				{
					String field = ds.toString(rsmd.getColumnName(i));
					String value = ds.toString(rs.getString(i));
					hash.put(field,value);
				}
				v_article.add(hash);//把焦点文章信息存入
				count++;
				if(count==num)break;
			}
		}catch(Exception e){System.out.println("MainBean.getGood(String id)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
	}
		return v_article;
	}

	//取得某一级版面下的焦点------------------------------------------------------------------------
	public Vector getGood(String id,String type)
	{
		Vector v_article = new Vector();
		
		//取得显示数量
		int num = getNUMfromMAINTABLE( type );
		String sql = ""; 
		ResultSet rs = null;

		//检索菜单表编号
		sql = getStrIDfromMENUTABLE( id , "" );
		if(sql.equals("")) return v_article;
		
		sql = "select id from article where whichtable='1' and ifshow='1' and ifgood ='1' and ORGANID='00000000000000000000' and menuid in ("+sql+")";
		
		sql = "select id,title,addtime,hits from article where id in ("+sql+") order by edittime desc";
		try
		{
			rs = selectRecord(sql);
			int i = 0;
			int count = 0 ;
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = 0;
			cols = rsmd.getColumnCount();	
			while(rs.next())
			{
				Hashtable hash = new Hashtable();
				for(int j=1;j<=cols;j++)
				{
					String field = ds.toString(rsmd.getColumnName(j));
					String value = ds.toString(rs.getString(j));
					hash.put(field,value);
				}
				v_article.add(hash);//把焦点文章信息存入
				count++;
				if(count==num)break;
			}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
	}
		return v_article;
	}

	//取得某一级版面下的焦点------------------------------------------------------------------------
	public Vector getGood(String id,String type,int cur,int records)
	{
		//检索菜单表编号
		//type=21焦点导读
		//type=22栏目精选

		int num = records;
		Vector v_article = new Vector();
		
		//取得显示数量
		int num1 = getNUMfromMAINTABLE( type );
		if( num1 != 0 ) num = num1 ;
		String sql = ""; 
		ResultSet rs = null;

		//检索菜单表编号
		sql = getStrIDfromMENUTABLE( id , "" );
		if(sql.equals("")) return v_article;


		sql = "select id from article where whichtable='1' and ifshow='1' and ifgood ='1' and ORGANID='00000000000000000000' and menuid in ("+sql+")";
		
		try
		{
			//计算总页数
			rs = selectRecord("select count(id) from article where id in ("+sql+") order by edittime desc");
			int rows = 0;
			if(rs.next())
				rows = rs.getInt(1);
			int sum = rows/records;
			if(rows%records!=0||rows==0)sum++;
			v_article.add(""+sum);
			v_article.add(""+rows);
			int pos = (cur-1)*records+1;
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("MainBean.getGood(String id,String type,int cur,int records)关闭记录集rs时出错"+e);}

			sql = "select id,title,addtime,hits from article where id in ("+sql+") order by edittime desc";
			rs = selectRecord(sql);
			int i = 0;
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = 0;
			cols = rsmd.getColumnCount();	
			while(rs.next())
			{
				i++;
				if(i<pos)continue;

				Hashtable hash = new Hashtable();
				for(int j=1;j<=cols;j++)
				{
					String field = ds.toString(rsmd.getColumnName(j));
					String value = ds.toString(rs.getString(j));
					hash.put(field,value);
				}
				v_article.add(hash);//把焦点文章信息存入
				if((v_article.size()-2)==num)break;
				if(i==rows)break;
			}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
	}
		return v_article;
	}


	//取得某专题下的所有文章---------------------------------------------------------------
	public Vector getOneTopic(String id)
	{
		Vector vect = new Vector();
		String sql = "";
		if(id.equals("0")) return vect;
		sql = " select ID,TITLE,ADDTIME,HITS from ARTICLE where TOPICID="+id+" and IFSHOW='1' order by edittime desc";

		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		//取得列数和列名
		ResultSetMetaData rsmd = rs.getMetaData();
		int cols = rsmd.getColumnCount();
		while(rs.next())
		{
			Hashtable hash = new Hashtable();
			for(int i=1;i<=cols;i++)
			{
				String field = ds.toString(rsmd.getColumnName(i));
				String value = ds.toString(rs.getString(i));
				hash.put(field,value);

⌨️ 快捷键说明

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