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

📄 mainbean.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	//生三级以下成树并返回根节点--------------------------------------------------------------------
	public Vector buildTree()
	{	

		Vector vt = new Vector();
		String sql =" Select * from MENU Where ID1 = "+id1+" and ID2 = "+id2+" and ID3 = 0";
		ResultSet rs1 = selectRecord(sql);
		Statement stmt = null;
		try{
		ResultSetMetaData rsmd1 = rs1.getMetaData();
		int cols1 = rsmd1.getColumnCount();
		if(rs1.next())
		{			

			Hashtable hash1 = new Hashtable();
			for (int i1 = 1; i1 <= cols1; i1++) 
			{
				String field1 = ds.toString(rsmd1.getColumnName(i1));
				String value1 = ds.toString(rs1.getString(i1));
				hash1.put(field1, value1);
			}
			DefaultMutableTreeNode root1 = new DefaultMutableTreeNode(hash1);//生成二级节点,二级版面
			sql = "select * from menu where id1="+id1+" and id2="+id2+" and id3!=0 order by id3";
			ResultSet rs2 = selectRecord(sql);
			MenuChildBean mcb = null;
			try{
			ResultSetMetaData rsmd2 = rs2.getMetaData();
			int cols2 = rsmd2.getColumnCount();	
			mcb = new MenuChildBean();		
			while(rs2.next())
			{
				Hashtable hash2 = new Hashtable();
				for (int i2 = 1; i2 <= cols2; i2++) 
				{
					String field2 = ds.toString(rsmd2.getColumnName(i2));
					String value2 = ds.toString(rs2.getString(i2));
					hash2.put(field2, value2);
				}
				DefaultMutableTreeNode root2 = new DefaultMutableTreeNode(hash2);//生成三级节点,三级版面
				String str = (String)hash2.get("ID");
				mcb.setParentID(Integer.parseInt(str));
				Vector child = mcb.buildTree();
				if(child.size()!=0)
				{
					for(int a=0;a<child.size();a++)
					{
						DefaultMutableTreeNode root3 = (DefaultMutableTreeNode)child.get(a);
						root2.add(root3);
					}
				}
				root1.add(root2);
			}
			vt.add(root1);
			}catch(Exception e){System.out.println("MainBean.buildTree()运行时出错:"+e);}
			finally{
				if(mcb!=null) mcb.closeConn();
				if(rs2!=null)try{ stmt = rs2.getStatement(); rs2.close();}catch(Exception e){System.out.println("MainBean.buildTree()关闭记录集rs时出错"+e);}
				if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.buildTree()关闭声明时statement出错"+e);}		
			}
		}
		}catch(Exception e){System.out.println("MainBean.buildTree()运行时出错:"+e);}
		finally{
			if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("MainBean.buildTree()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.buildTree()关闭声明时statement出错"+e);}		
		}
		return vt;
	}	


	//取得所有首页图片新闻-------------------------------------------------------------------------------
	public Vector getPicNew()
	{
		Vector vect = new Vector();
		String sql = "";
		sql = " select ID,TITLE,ADDTIME,HITS from ARTICLE where IFSHOW = '1' and IFIMG='1' and IFHEAD='1' 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.getPicNew()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getPicNew()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getPicNew()关闭声明时statement出错"+e);}		
		}
		return vect;
	}

	//取得某一版面的首页图片新闻----------------------------------------------------------
	public Vector getPicNew(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 IFIMG='1' and ifhead ='1' and ORGANID='00000000000000000000' and menuid in ("+sql+")";
		sql = "select id,title,addtime,hits,img from article where id in ("+sql+") order by edittime desc";

		try
		{
			rs = selectRecord(sql);
			int count = 0 ;
			int i = 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.getPicNew(String id)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("MainBean.getPicNew(String id)关闭记录集rs时出错"+e);}
		}
		return v_article;
	}


	//设置默认Css格式时,修改数据表
	public void setMrCss(String cssstyle)
	{
		String sql = "";
		sql = "update NB_YSB set ISNOW=0 where STYLE!='"+cssstyle+"'";
		deleteRecord(sql);
		sql = "update NB_YSB set ISNOW=1 where STYLE='"+cssstyle+"'";
		deleteRecord(sql);
	}


	//取得显示图片新闻的数目-----------------------------------------------------------------	
	public int getPicNum()
	{
		String sql = "";
		String s = "0";
		sql = "select NUM from NB_TPSZB";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			s= ds.toString(rs.getString("NUM"));
		}
		}catch(Exception e){System.out.println("MainBean.getPicNum()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getPicNum()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getPicNum()关闭声明时statement出错"+e);}		
		}
		return Integer.parseInt(s);
	}
	

	//取得显示图片新闻的高度-----------------------------------------------------------------
	public int getPicHeight()
	{
		String sql = "";
		String s ="0";
		sql = "select HEIGHT from NB_TPSZB";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			 s= ds.toString(rs.getString("HEIGHT"));
		}
		}catch(Exception e){System.out.println("MainBean.getPicHeight()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getPicHeight()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getPicHeight()关闭声明时statement出错"+e);}		
		}
		return Integer.parseInt(s);
	}


	//取得显示图片新闻的宽度----------------------------------------------------------------
	public int getPicWidth()
	{
		String sql = "";
		String s = "0";
		sql = "select WIDTH from NB_TPSZB";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			s = ds.toString(rs.getString("WIDTH"));
		}
		}catch(Exception e){System.out.println("MainBean.getPicWidth()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getPicWidth()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getPicWidth()关闭声明时statement出错"+e);}		
		}
		return Integer.parseInt(s);
	}


	//取得所有公开的专题
	public Vector getTopic()
	{
		Vector vect = new Vector();
		String sql = "";

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


	//取得某一版面下的公开的专题
	public Vector getTopic(String menuid1)
	{
		Vector vect = new Vector();
		String sql =  "select * from NB_TOPIC where STATUS = 0 and MENUID1='"+menuid1+"' order by JBXH";
		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.getTopic(String muname)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getTopic(String muname)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getTopic(String muname)关闭声明时statement出错"+e);}		
		}
		return vect;
	}

	//取得一级版面下的设置显示的新闻条数-----------------------------------------------------------------
	public int getNewsNum(String i)
	{
		String sql = "";
		int num = 0;
		sql = "select NUM from NB_ZYSZB where ID = "+i+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			String str = ds.toString(rs.getString("NUM"));		
			num = Integer.parseInt(str);
		}
		}catch(Exception e){System.out.println("MainBean.getNewsNum(String i)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getNewsNum(String i)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getNewsNum(String i)关闭声明时statement出错"+e);}		
		}
		return num;
	}


	//取得一级版面的新闻后面是否显示时间----------------------------------------------------------------
	public boolean isShowTime(String i)
	{
		String sql = "";
		String str = "";
		sql = "select ISSHOWTIME from NB_ZYSZB where ID = "+i+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			str = ds.toString(rs.getString("ISSHOWTIME"));
		}
		}catch(Exception e){System.out.println("MainBean.isShowTime(String i)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.isShowTime(String i)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.isShowTime(String i)关闭声明时statement出错"+e);}		
		}
		if(str.equals("1"))
			return true;
		else 
			return false;
	}


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

		sql = " select distinct a.ID,a.NUM,a.ISSHOWTIME,b.MENU1 from nb_zyszb a,menu b where a.id=b.id1 ";
		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(""))
		{

⌨️ 快捷键说明

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