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

📄 mainbean.java

📁 运用java+jsp写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	}


	//取得主页设置中的所有信息-----------------------------------------------------------------------
	public Vector getMain()
	{
		Vector vect = new Vector();
		String sql = "";

		sql = " select * from NB_ZYSZB order by 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.getMain()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getMain()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getMain()关闭声明时statement出错"+e);}		
		}
		return vect;
	}


	//根据某文章ID取得某一篇文章信息--------------------------------------------------------------
	public Hashtable getOneNews(String id)
	{
		Hashtable hash = new Hashtable();
		String sql = "";
		if(id.equals(""))
		{
			return null;
		}
		sql = "select * 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,MENUID,TITLE,TOPICID,FROMSITE,WRITER,ADDTIME,KEYWORD,IFHEAD,IFGOOD,IFSHOW,IMG,HITS,ORGID,EDITER,EDITTIME,EDITIP,TIMES,FTPFILE,WHICHTABLE,DEMOID,IFIMG,VOTE,ORGANID,WZLX,AUTHOR,OLDORGID,STRSIZE,CURSIZE 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();
		int t=0;
		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.getOnePage1(sql,page,records,false);
		//return db.getOnePage(sql,page,records);
	}

	
	//取得二级以下菜单的名称--------------------------------------------------------------
	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 * 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)
	{
		//检索菜单表编号

		String sql = "select num from nb_zyszb where id="+id; 
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		Vector v_article = new Vector();
		int num = 0;
		try{
		if(rs.next())
			num = rs.getInt(1);
		//if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
		//if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭声明时statement出错"+e);}		
		sql = "select ID from Menu where id3<>0 and Id1="+id;
		rs = selectRecord(sql);
		Vector v_menu = new Vector();
		while(rs.next())
		{
			v_menu.add(rs.getString("ID"));
		}

		//if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
		//if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭声明时statement出错"+e);}		
		
		if(v_menu.isEmpty()) return v_menu;
		//检索子菜单表编号
		sql = "select ID from menuchild where isthis=0 and IDPARENT in (select ID from Menu where id3<>0 and Id1="+id+")";
		rs = selectRecord(sql);
		Vector v_child = new Vector();
		while(rs.next())
		{
			String id4 = rs.getString("ID");
			v_child.add(id4);
			Stack s4 = new Stack();
			s4.push(id4);

			while(!s4.empty())//当有孩子节点时继续搜索
			{
				id4 = (String)s4.pop();
				sql = "select count(id) from menuchild where isthis=1 and IDPARENT="+id4;
				ResultSet rs4 = selectRecord(sql);
				int count = 0;
				try{
					if(rs4.next())
						count = rs4.getInt(1);
					if(count>0)
					{
						sql = "select id from menuchild where isthis=1 and  IDPARENT="+id4;					
						ResultSet rs_t = selectRecord(sql);
						try{
							while(rs_t.next())
							{
								String id_t = rs_t.getString("id");	
								s4.push(id_t);
								v_child.add(id_t);
							}
						}catch(Exception e){System.out.println("MainBean.getGood(String id)运行时出错:"+e);}
						finally{
							if(rs_t!=null)try{ stmt = rs_t.getStatement(); rs_t.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
							if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭声明时statement出错"+e);}		
						}
					}
				}catch(Exception e){System.out.println("MainBean.getGood(String id)运行时出错:"+e);}
				finally{
					if(rs4!=null)try{ stmt = rs4.getStatement(); rs4.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
					if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭声明时statement出错"+e);}		
				}
			}
		}

		//if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭记录集rs时出错"+e);}
		//if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getGood(String id)关闭声明时statement出错"+e);}		
		//检索文章编号
		sql = "";
		for(int i=0;i<v_menu.size();i++)
		{
			if(!sql.equals(""))sql += ",";
			sql += (String)v_menu.get(i);
			//if(!sql.equals(""))sql += " union ";
			//sql += "select id from article where whichtable='1' and ifshow='1' and ifgood ='1' and ORGANID='00000000000000000000' and menuid="+(String)v_menu.get(i);
		}
		for(int i=0;i<v_child.size();i++)
		{
			if(!s

⌨️ 快捷键说明

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