📄 linknews.java
字号:
package com.ntsky.news;
import com.ntsky.common.Debug;
import com.ntsky.database.SQLDBOperator;
import com.ntsky.persistence.*;
import com.ntsky.common.CodeFilter;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
public class LinkNews {
public SQLDBOperator sdbo;
public LinkNews() {
sdbo = null;
}
public void insNEWSClass(String content, String imagPath, String flag,String selectIndex) {
if (sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "insert into newsClass(content,imagPath,flag,indexSelect) values(?,?,?,?)";;
try {
if (Integer.parseInt(flag) == 1) {
String selectSql = "select * from newsClass where indexSelect=?";
sdbo.prepareStatement(selectSql);
sdbo.setInt(1, Integer.parseInt(selectIndex));
ResultSet rs1 = sdbo.executeQuery();
rs1.last();
if (rs1.getRow() > 0) {
String updateSql = "update newsClass set flag=0,indexSelect=-1 where indexSelect=?";
sdbo.prepareStatement(updateSql);
sdbo.setInt(1, Integer.parseInt(selectIndex));
sdbo.executeUpdate();
sdbo.Close();
}
}
sdbo.prepareStatement(strSql);
sdbo.setString(1, CodeFilter.toHtml(content));
sdbo.setString(2, CodeFilter.toHtml(imagPath));
sdbo.setInt(3, Integer.parseInt(flag));
if (Integer.parseInt(flag) == 1) {
sdbo.setInt(4, Integer.parseInt(selectIndex));
}else{
sdbo.setInt(4,-1);
}
sdbo.executeUpdate();
PageCache.getInstance().addClassItemToCache();
} catch (Exception e) {
System.out.print("UserNews insNEWSClass() :" + e.getMessage());
Debug.writeLog("UserNews insNEWSClass(), Exception Occured ! Info :" + e.getLocalizedMessage());
} finally {
sdbo.Close();
}
}
public void delNewsClass(int classId) {
if (sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "delete from newsClass where classId='" + classId + "';";
try {
sdbo.executeUpdate(strSql);
PageCache.getInstance().delClassToCache(String.valueOf(classId));
} catch (Exception e) {
System.out.print("UserNews delUserNews() :" + e.getMessage());
Debug.writeLog("UserNews delUserNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
} finally {
sdbo.Close();
}
}
public int sumClass() {
ResultSet rs = null;
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
int sum = 0;
String sql = "select count(classId) as sum from newsClass;";
try {
sdbo.prepareStatement(sql);
rs = sdbo.executeQuery();
rs.next();
sum = rs.getInt("sum");
rs.close();
} catch (SQLException sqlE) {
System.out.print("Personal sumUnNews() info :" + sqlE.getMessage());
Debug.writeLog("Personal sumUnNews(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} catch (NullPointerException nullE) {
System.out
.print("Personal sumUnNews() info :" + nullE.getMessage());
Debug.writeLog("Personal sumUnNews(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return sum;
}
public Iterator showClass() {
Vector vector = new Vector();
ResultSet rs = null;
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "select * from newsclass order by indexSelect desc;";
try {
rs = sdbo.executeQuery(strSql);
while (rs.next()) {
NEWSClass tableClass = new NEWSClass();
tableClass.setClassId(rs.getInt("classId"));
tableClass.setContent(CodeFilter.toUbbHtml(new String(rs.getString("content").getBytes("ISO-8859-1"),"gbk")));
tableClass.setIdex(String.valueOf(rs.getInt("indexSelect")));
vector.add(tableClass);
}
rs.close();
} catch (SQLException sqlE) {
System.out.print("NewsShow sumNews() " + sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
sdbo.Close();
}
return vector.iterator();
}
public boolean isConnectLink(String connect) {
boolean isLink = false;
ResultSet rs = null;
if (sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "select newsId from news where state=1 and connect like '%" + connect + "%';";
try {
rs = sdbo.executeQuery(strSql);
try {
rs.last();
if (rs.getRow() > 0)isLink = true;
rs.close();
} catch (NullPointerException nullE) {
System.out.print("NewsShow sumNews() " + nullE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
} catch (SQLException sqlE) {
System.out.print("NewsShow sumNews() " + sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return isLink;
}
public Iterator connectLink(String connect) {
Vector vector = new Vector();
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs = null;
String strSql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time from news where state=1 and connect like '%"
+ connect + "%' order by newstime desc limit 0,8;";
try {
rs = sdbo.executeQuery(strSql);
try {
while (rs.next()) {
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setNewsTime(rs.getString("time"));
vector.add(tableNews);
}
rs.close();
} catch (NullPointerException nullE) {
System.out.print("NewsShow sumNews() " + nullE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
}
} catch (SQLException sqlE) {
System.out.print("NewsShow sumNews() " + sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return vector.iterator();
}
public boolean isKind(int classId) {
boolean isKind = false;
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs = null;
String strSql = "select kindId from newskind where classId=?;";
try {
sdbo.prepareStatement(strSql);
sdbo.setInt(1, classId);
rs = sdbo.executeQuery();
try {
rs.last();
if (rs.getRow() > 0)
isKind = true;
rs.close();
} catch (NullPointerException nullE) {
System.out.print("NewsShow sumNews() " + nullE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
}
} catch (SQLException sqlE) {
System.out.print("NewsShow sumNews() " + sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return isKind;
}
public Iterator kindShow(int classId) {
Vector vector = new Vector();
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs = null;
String strSql = "select * from newskind where classId=? order by kindId asc;";
try {
sdbo.prepareStatement(strSql);
sdbo.setInt(1, classId);
rs = sdbo.executeQuery();
while (rs.next()) {
NEWSKind tableKind = new NEWSKind();
tableKind.setKindId(rs.getInt("kindId"));
tableKind.setContent(new String(rs.getString("content").getBytes("ISO-8859-1"), "gbk"));
tableKind.setClassId(rs.getInt("classId"));
vector.add(tableKind);
}
rs.close();
} catch (SQLException sqlE) {
System.out.print("NewsShow sumNews() " + sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -