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

📄 column.java

📁 动态网站管理发布系统
💻 JAVA
字号:
package com.ntsky.news.manage;

import com.ntsky.common.CodeFilter;
import com.ntsky.common.Debug;
import com.ntsky.database.SQLDBOperator;
import com.ntsky.persistence.NEWSClass;
import com.ntsky.news.PageCache;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

public class Column {

	private SQLDBOperator sdbo;

	public Column() {
		sdbo = null;
	}

	public boolean isNullColumn() {
		boolean isNull = false;
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		ResultSet rs = null;
		String Sql = "select classId from newsclass;";
		try {
			rs = sdbo.executeQuery(Sql);
			try {
				rs.last();
				if (rs.getRow() > 0)
					isNull = true;
			} catch (NullPointerException nullE) {
				nullE.printStackTrace(System.out);
				Debug
						.writeLog("Column inNullColumn(), Exception Occured ! Info :"
								+ nullE.getLocalizedMessage());
			}
		} catch (SQLException sqlE) {
			sqlE.printStackTrace(System.out);
			Debug.writeLog("Column inNullColumn(), Exception Occured ! Info :"
					+ sqlE.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
		return isNull;
	}

	public Iterator getColumn() {
		ResultSet rs = null;
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		Vector vector = new Vector();
		String Sql = "select classId,content from newsclass;";
		try {
			rs = sdbo.executeQuery(Sql);
			while (rs.next()) {
				NEWSClass tableClass = new NEWSClass();
				tableClass.setClassId(rs.getInt("classId"));
				tableClass.setContent(new String(rs.getString("content")
						.getBytes("ISO-8859-1"), "gbk"));
				vector.add(tableClass);
			}
			rs.close();
		} catch (SQLException sqlE) {
			sqlE.printStackTrace(System.out);
			Debug.writeLog("Column getColumn(), Exception Occured ! Info :"
					+ sqlE.getLocalizedMessage());
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		sdbo.Close();
		return vector.iterator();
	}

	public boolean isIns(int classId) {
		boolean isIns = false;
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		String strSql = "select * from newsclass where classId=?";
		try {
			sdbo.prepareStatement(strSql);
			sdbo.setInt(1, classId);
			ResultSet rs = sdbo.executeQuery();
			rs.last();
			if (rs.getRow() > 0)
				isIns = true;
			rs.close();

		} catch (SQLException sqlE) {
			System.out.print("Column isIns():" + sqlE.getMessage());
			Debug.writeLog("Column isIns(), Exception Occured ! Info :"
					+ sqlE.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
		return isIns;
	}

	public void InsColumn(int classId, String content) {
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		try {
			String strSql = "insert into newsclass(classId,content) values(?,?);";
			sdbo.prepareStatement(strSql);
			sdbo.setInt(1, classId);
			sdbo.setString(2, CodeFilter.toHtml(content));
			sdbo.executeUpdate();
		} catch (Exception e) {
			System.out.print("Column delColumn() :" + e.getMessage());
			Debug.writeLog("Column delColumn() , Exception Occured ! Info :"
					+ e.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
	}

	public void delColumn(int classId) {
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		String strSql_class = "delete from newsclass where classId=?";
		String strSql_kind = "delete from newskind where classId=?";
		String strSql_news = "delete from news where classId=?";
		String strSql_news_newsId = "select newsId from news where classId=?";
		String strSql_reply = "delete from newsreply where newsId=?";
		try {
			sdbo.prepareStatement(strSql_class);
			sdbo.setInt(1, classId);
			sdbo.executeUpdate();
			sdbo.prepareStatement(strSql_kind);
			sdbo.setInt(1, classId);
			sdbo.executeUpdate();
			sdbo.prepareStatement(strSql_news);
			sdbo.setInt(1, classId);
			sdbo.executeUpdate();
			sdbo.prepareStatement(strSql_news_newsId);
			sdbo.setInt(1, classId);
			ResultSet rs = sdbo.executeQuery();
			sdbo.prepareStatement(strSql_reply);
			for (; rs.next(); sdbo.executeUpdate()) {
				int newsId = rs.getInt("newsId");
				sdbo.setInt(1, newsId);
			}
		} catch (SQLException sqlE) {
			System.out.print("Column delColumn() :" + sqlE.getMessage());
			Debug.writeLog("Column delColumn() , Exception Occured ! Info :"
					+ sqlE.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
	}

	public Iterator editColumn(int classId) {
		ResultSet rs = null;
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		Vector vector = new Vector();
		String strSql = "select classId,content,imagPath,flag,indexSelect from newsclass where classId=?";
		try {
			sdbo.prepareStatement(strSql);
			sdbo.setInt(1, classId);
			rs = sdbo.executeQuery();
			while (rs.next()) {
				NEWSClass tableClass = new NEWSClass();
				tableClass.setClassId(rs.getInt("classId"));
				tableClass.setContent(new String(rs.getString("content").getBytes("ISO-8859-1"), "gbk"));
				tableClass.setImagPath(rs.getString("imagPath"));
				tableClass.setIsValidate(String.valueOf(rs.getInt("flag")));
				tableClass.setIdex(String.valueOf(rs.getInt("indexSelect")));
				vector.add(tableClass);
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException sqlE) {
			System.out.print("Column isIns() :" + sqlE.getMessage());
			Debug.writeLog("Column isIns() , Exception Occured ! Info :"
					+ sqlE.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
		return vector.iterator();
	}

	public void upColumn(int classId, String content, String imagPath,String flag,String index,String orgIndexSelect) {
		if (sdbo == null) sdbo = SQLDBOperator.getInstance("Connection");
		String strSql = "update newsclass set content=?,imagPath=?,flag=?,indexSelect=? where classId=?;";
		if(imagPath == null||"".equals(imagPath)){
			strSql = "update newsclass set content=?,flag=?,indexSelect=? where classId=?;";
		}
		try {
			if (Integer.parseInt(flag) == 1) {
				String selectSql = "select * from newsClass where indexSelect=?";

				sdbo.prepareStatement(selectSql);
				sdbo.setInt(1, Integer.parseInt(index));
				ResultSet rs1 = sdbo.executeQuery();
				rs1.last();
				if (rs1.getRow() > 0) {
					sdbo.Close();
					
					String updateSql = null;
					if(Integer.parseInt(orgIndexSelect) == -1){
						updateSql = "update newsClass set flag=0,indexSelect=-1 where indexSelect=?";
						sdbo.prepareStatement(updateSql);
						sdbo.setInt(1, Integer.parseInt(index));						
					}else{
						updateSql = "update newsClass set flag=1,indexSelect=? where indexSelect=?";
						sdbo.prepareStatement(updateSql);
						sdbo.setInt(1, Integer.parseInt(orgIndexSelect));
						sdbo.setInt(2, Integer.parseInt(index));												
					}
					sdbo.executeUpdate();
					sdbo.Close();
				}

				strSql = null;
				strSql = "update newsclass set content=?,imagPath=?,flag=?,indexSelect=? where classId=?;";
				if(imagPath == null||"".equals(imagPath)){
					strSql = "update newsclass set content=?,flag=?,indexSelect=? where classId=?;";
				}				
			}

			sdbo.prepareStatement(strSql);
			sdbo.setString(1, CodeFilter.toHtml(content));
			if(imagPath != null&&!"".equals(imagPath)){
				sdbo.setString(2, imagPath);
				sdbo.setInt(3, Integer.parseInt(flag));
				sdbo.setInt(4, Integer.parseInt(index));
				sdbo.setInt(5, classId);				
			}else{
			    sdbo.setInt(2, Integer.parseInt(flag));
			    sdbo.setInt(3, Integer.parseInt(index));
			    sdbo.setInt(4, classId);
			}
			sdbo.executeUpdate();
			PageCache.getInstance().addClassItemToCache();
			//PageCache.getInstance().updateClassItemToCache(classId,Integer.parseInt(flag),Integer.parseInt(index),Integer.parseInt(orgIndexSelect),content);
		} catch (Exception e) {
			System.out.print("Column upColumn() :" + e.getMessage());
			Debug.writeLog("Column upColumn() , Exception Occured ! Info :" + e.getLocalizedMessage());
		} finally {
			sdbo.Close();
		}
	}

	public String getColumn_newsShow(int classId) {
		if (sdbo == null)
			sdbo = SQLDBOperator.getInstance("Connection");
		ResultSet rs = null;
		String content = null;
		String strSql = "select content from newsclass where classId='"
				+ classId + "';";
		try {
			rs = sdbo.executeQuery(strSql);
			rs.next();
			content = new String(
					rs.getString("content").getBytes("ISO-8859-1"), "gbk");
		} catch (SQLException sqlE) {
			System.out.print("Column getColumn_newsShow(int classId) :"
					+ sqlE.getMessage());
			Debug
					.writeLog("Column getColumn_newsShow(int classId) , Exception Occured ! Info :"
							+ sqlE.getLocalizedMessage());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			sdbo.Close();
		}
		return content;
	}
}

⌨️ 快捷键说明

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