📄 reply.java
字号:
package com.ntsky.news;
import com.ntsky.common.*;
import com.ntsky.database.SQLDBOperator;
import com.ntsky.persistence.NEWSReply;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
public class Reply {
private SQLDBOperator sdbo;
private ResultSet rs;
public Reply() {
sdbo = null;
rs = null;
}
public void insReply(int newsId, String user, String content) {
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "insert into newsreply(newsId,user,content,replyTime) values(?,?,?,?);";
try {
sdbo.prepareStatement(strSql);
sdbo.setInt(1, newsId);
sdbo.setString(2, CodeFilter.toHtml(user));
sdbo.setString(3, CodeFilter.toHtml(content));
sdbo.setString(4, DateUtil.getStringDateShort());
sdbo.executeUpdate();
} catch (Exception e) {
System.out.print("Reply insReply() " + e.getMessage());
Debug.writeLog("Reply insReply(), Exception Occured ! Info :"
+ e.getLocalizedMessage());
} finally {
sdbo.Close();
}
}
public boolean isReply(int newsId) {
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
boolean isReply = false;
String strSql = "select replyId from newsreply where newsId=?;";
try {
sdbo.prepareStatement(strSql);
sdbo.setInt(1, newsId);
rs = sdbo.executeQuery();
try {
rs.last();
if (rs.getRow() > 0)
isReply = true;
rs.close();
} catch (NullPointerException nullE) {
System.out.print("Reply listReply() " + nullE.getMessage());
Debug.writeLog("Reply listReply(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
}
} catch (SQLException sqlE) {
System.out.print("Reply listReply() " + sqlE.getMessage());
Debug.writeLog("Reply listReply(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return isReply;
}
public Iterator listReply(int newsId) {
Vector vector = new Vector();
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "select * from newsreply where newsId=?;";
try {
sdbo.prepareStatement(strSql);
sdbo.setInt(1, newsId);
rs = sdbo.executeQuery();
while (rs.next()) {
NEWSReply tableReply = new NEWSReply();
tableReply.setNewsId(rs.getInt("newsId"));
tableReply.setContent(new String(rs.getString("content")
.getBytes("ISO-8859-1"), "gbk"));
tableReply.setUser(new String(rs.getString("user").getBytes(
"ISO-8859-1"), "gbk"));
tableReply.setReplyTime(rs.getString("replyTime"));
vector.add(tableReply);
}
rs.close();
} catch (SQLException sqlE) {
System.out.print("Reply listReply() " + sqlE.getMessage());
Debug.writeLog("Reply listReply(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} catch (UnsupportedEncodingException nullE) {
System.out.print("Personal unNews() info :" + nullE.getMessage());
Debug.writeLog("Personal unNews(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return vector.iterator();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -