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

📄 mainbean.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}
			vect.add(hash);
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return vect;
	}

	//取得某专题下的所有文章---------------------------------------------------------------
	public Vector getOneTopic(String id,int cur,int records)
	{
		Vector vect = new Vector();
		String sql = "";
		if(id.equals("0")) return vect;

		//计算总页数
		sql = " select count(*) from ARTICLE where TOPICID="+id+" and IFSHOW='1' order by edittime desc";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		rs.next();
		int rows = rs.getInt(1);
		int sum = rows/records;
		if(rows%records!=0||rows==0)sum++;
		vect.add(""+sum);
		vect.add(""+rows);
		int pos = (cur-1)*records+1;
		if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("MainBean.getOneTopic(String id,int cur,int records)关闭记录集rs时出错"+e);}
		if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("MainBean.getOneTopic(String id,int cur,int records)关闭声明时statement出错"+e);}		
		sql = " select ID,TITLE,ADDTIME,HITS from ARTICLE where TOPICID="+id+" and IFSHOW='1' 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++)
			{
				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);//把焦点文章信息存入
			if((vect.size()-2)==records)break;
			if(i==rows)break;
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return vect;
	}


	//增加新闻评论表数据记录--------------------------------------------------------------
	public int addCom(Hashtable hash)
	{			
		int intMax = db.makeID("COMMENTB","ID","","",true);
		String strArticleid = ds.toString((String)hash.get("ARTICLEID"));
		String strComment = ds.toGBK((String)hash.get("CONTENT"));
		String strTime = ds.getDateTime();
		String strCritic = ds.toString((String)hash.get("CRITIC"));
        
		Vector vect =new Vector();
		vect.add("COMMENTB");
		vect.add(addVector("ID",String.valueOf(intMax),"NUM"));
		vect.add(addVector("ARTICLEID",strArticleid,"NUM"));
		vect.add(addVector("CONTENT",strComment,"CHAR"));
		vect.add(addVector("TIME",strTime,"CHAR"));
		vect.add(addVector("CRITIC",strCritic,"CHAR"));
	
		return insertRecord(vect);
	}	
	

	//得到某评论文章的内容----------------------------------------------------------------
	public String getComCon(String id)
	{
		String content = "";
		String sql = "";
		sql = "select CONTENT from COMMENTB where id='"+id+"'";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			content = ds.toString(rs.getString("CONTENT"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return content;
	}


	//把风格转化为文件名	
	public String styleToname (String style)
	{
		String sql = "";
		String filename ="";
		sql = "select FILENAME from NB_YSB where STYLE = '"+style+"'";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			filename = ds.toString(rs.getString("FILENAME"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return filename;
	}

    
	//增加访问次数--------------------------------------------------------------------
	public int addTime(String id)
	{
		String sql = "";
		String strtimes = "";
		if(id.equals(""))
		{
			return -1;
		}
		int inttimes =0;
		sql = "select TIMES from article where ID = "+id+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			strtimes  = ds.toString(rs.getString("TIMES"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		if(strtimes.equals("")) strtimes = "0";
		inttimes = Integer.parseInt(strtimes);
		inttimes+=1;
		strtimes = String.valueOf(inttimes);
		sql = "update article set TIMES="+strtimes+" where ID = "+id+"";
		return deleteRecord(sql);
	}


	//得到ftp地址
	public String getftpsite()
	{
		String sql = "";
		String ftpsite = "";
		sql = "select FTPIP from NB_FTPSET";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			ftpsite  = ds.toString(rs.getString("FTPIP"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return ftpsite;
	}


	//取得某一个二级版面下的所有文章信息---------------------------------------------------
	public Vector getArticle(String id1,String id2)
	{
		Vector v_article = new Vector();
		
		//取得显示数量
		int num = getNUMfromMAINTABLE( id1 );
		String sql = ""; 
		ResultSet rs = null;

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

		sql = "select id from article where whichtable='1' and ifshow='1' and ifhead='1' and ORGANID='00000000000000000000' and menuid in ("+sql+")";
		sql = "select id,title,addtime,hits from article where ifhead='1' and 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("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
	}
		return v_article;
	}


	//根据专题编号返回专题名称-----------------------------------------------------------------
	public String getTopicName(String topicid)
	{
		String sql = "";
		String topicname = "";
		sql = "select NAME from nb_topic where id = "+topicid+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			topicname  = ds.toString(rs.getString("NAME"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		return topicname;
	}


	//是否可以发表评论-------------------------------------------------------------------------
	public boolean ifCanCom()
	{
		String sql = "";
		String strisfree = "";
		sql = "select isfree from ComConfB";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			strisfree  = ds.toString(rs.getString("isfree"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		if(strisfree.equals("1")) return true;
		else return false;


	}

	//取得某版面的设置情况
	public Hashtable getOneMenuConf(String id)
	{
		Hashtable hash = new Hashtable();
		String sql = "";

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


	//根据文章id取得文章的版面全路经
	public String getArcPath(String id)
	{
		String path = "";
		String menuid = "";
		String sql = "";
		String wib = "";
		String menu1 = "";
		String menu2 = "";
		String menu3 = "";
		
		String MenuChildName = "";//存放三级以下菜单名字
		sql = "select menuid,whichtable from article where id = "+id+"";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			menuid = ds.toString(rs.getString("MENUID"));//取得最底层版面
			wib = ds.toString(rs.getString("WHICHTABLE"));
		}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		if(menuid.equals("")) return path;
	
		//取得三级以下菜单名
		if(wib.equals("0"))
		{
			String transid = menuid;
			String strname = "";
			String isthis = "1";
			while(isthis.equals("1"))
			{
				sql = "select IDPARENT,MENUCHILD,ISTHIS from MENUCHILD where id = "+transid+"";
				ResultSet rs1 = selectRecord(sql);
				try{
				if(rs1.next())
				{
					transid = ds.toString(rs.getString("IDPARENT"));
					strname = ds.toString(rs.getString("MENUCHILD"));
					MenuChildName += strname+",";
					isthis = ds.toString(rs.getString("ISTHIS"));
				}
				}catch(Exception e){System.out.println("运行时出错:"+e);}
				finally{
					if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
					if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
				}
			}
			menuid = transid;
		}

		String menuname[] = MenuChildName.split(",");
		MenuChildName="";
		int i = menuname.length-1;
		while(i<0)
		{
			MenuChildName +=" >> " +  menuname[i];
			i--;
		}
		

		//在menu表中查询

⌨️ 快捷键说明

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