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

📄 mainbean.java

📁 这是一个很好用的软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					} catch (Exception e) {
						System.out.println("运行时出错:" + e);
					} finally {
						if (rs4 != null)
							try {
								stmt = rs4.getStatement();
								rs4.close();
							} catch (Exception e) {
								System.out.println("关闭记录集rs时出错" + e);
							}
						if (stmt != null)
							try {
								stmt.close();
							} catch (Exception e) {
								System.out.println("关闭声明时statement出错" + e);
							}
					}
				}
			}
			//if(rs!=null)try{ stmt = rs.getStatement();
			// rs.close();}catch(Exception
			// e){System.out.println("MainBean.getGood(String id,String type,int
			// cur,int records)关闭记录集rs时出错"+e);}
			//if(stmt!=null) try{stmt.close();}catch(Exception
			// e){System.out.println("MainBean.getGood(String id,String type,int
			// cur,int records)关闭声明时statement出错"+e);}
			//检索文章编号
			sql = "";
			for (int i = 0; i < v_menu.size(); i++) {
				if (!sql.equals(""))
					sql += " union ";
				sql += "select id from news.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 (!sql.equals(""))
					sql += " union ";
				sql += "select id from article where whichtable='0' and ifshow='1' and ifgood ='1' and ORGANID='00000000000000000000' and menuid="
						+ (String) v_child.get(i);
			}

			//计算总页数
			rs = selectRecord("select count(id) from news.article where id in ("
					+ sql + ") ");
			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{ stmt = rs.getStatement();
			// rs.close();}catch(Exception
			// e){System.out.println("MainBean.getGood(String id,String type,int
			// cur,int records)关闭记录集rs时出错"+e);}
			//if(stmt!=null) try{stmt.close();}catch(Exception
			// e){System.out.println("MainBean.getGood(String id,String type,int
			// cur,int records)关闭声明时statement出错"+e);}
			sql = "select id,title,addtime,hits from news.article where id in ("
					+ sql + ") ";
			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{ 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 (rs != null)
			try {
				stmt = rs.getStatement();
				rs.close();
			} catch (Exception e) {
				System.out.println("MainBean.getArticle(String id)关闭记录集rs时出错"
						+ e);
			}
		if (stmt != null)
			try {
				stmt.close();
			} catch (Exception e) {
				System.out
						.println("MainBean.getArticle(String id)关闭声明时statement出错"
								+ e);
			}

		return v_article;
	}

	//取得某专题下的所有文章---------------------------------------------------------------
	public Vector getOneTopic(String id) {
		Vector vect = new Vector();
		String sql = "";
		if (id.equals("0"))
			return vect;
		sql = " select * from news.ARTICLE where TOPICID=" + id
				+ " and IFSHOW='1' order by edittime desc";
		ResultSet rs = selectRecord(sql);
		return getResultSetData(rs);
	}

	//取得某专题下的所有文章---------------------------------------------------------------
	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 news.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;
			sql = " select * from news.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);
				}
		}
		if (rs != null)
			try {
				stmt = rs.getStatement();
				rs.close();
			} catch (Exception e) {
				System.out.println("MainBean.getArticle(String id)关闭记录集rs时出错"
						+ e);
			}
		if (stmt != null)
			try {
				stmt.close();
			} catch (Exception e) {
				System.out
						.println("MainBean.getArticle(String id)关闭声明时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.toString((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 news.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 = "select FILENAME from news.NB_YSB where STYLE = '" + style
				+ "'";
		ResultSet rs = selectRecord(sql);
		return getStrByResultSet(rs, "FILENAME");
	}

	//增加访问次数--------------------------------------------------------------------
	public int addTime(String id) {
		String sql = "";
		String strtimes = "";
		if (id.equals("")) {
			return -1;
		}
		int inttimes = 0;
		sql = "select TIMES from news.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 news.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) {
		//检索菜单表编号
		String sql = "select num from news.nb_zyszb where id=" + id1;
		ResultSet rs = selectRecord(sql);
		Vector v_article = new Vector();
		Statement stmt = null;
		try {
			int num = 0;
			if (rs.next())
				num = rs.getInt(1);
			sql = "select ID from news.Menu where Id3!=0 and Id1=" + id1
					+ " and Id2=" + id2;

			rs = selectRecord(sql);
			Vector v_menu = new Vector();
			while (rs.next()) {
				v_menu.add(rs.getString("ID"));
			}
			if (v_menu.isEmpty())
				return v_menu;
			//检索子菜单表编号
			sql = "select ID from news.menuchild where isthis=0 and IDPARENT in (select ID from news.Menu where Id3!=0 and id1="
					+ id1 + " and Id2=" + id2 + ")";

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

⌨️ 快捷键说明

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