📄 comment.java
字号:
package cn.js.fan.module.cms;
import org.apache.log4j.Logger;
import cn.js.fan.db.Conn;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import cn.js.fan.web.Global;
import cn.js.fan.util.DateUtil;
import com.redmoon.forum.SequenceMgr;
public class Comment implements java.io.Serializable {
String content,ip,nick,link;
int id;
int doc_id;
String add_date;
String connname = "";
transient Logger logger = Logger.getLogger(Comment.class.getName());
private static final String INSERT =
"INSERT into comment (nick, link, content, ip, doc_id, add_date,id) VALUES (?,?,?,?,?,?,?)";
private static final String LOAD =
"SELECT id,nick,content,link,ip,add_date,doc_id from comment WHERE id=?";
private static final String DEL =
"delete FROM comment WHERE id=?";
public Comment() {
connname = Global.defaultDB;
if (connname.equals(""))
logger.info("Comment:DB is empty!");
}
public Comment(int id) {
this.id = id;
connname = Global.defaultDB;
if (connname.equals(""))
logger.info("Comment:DB is empty!");
load(id);
}
public void renew() {
logger = Logger.getLogger(Comment.class.getName());
}
public boolean insert(int doc_id, String nick, String link, String content, String ip) {
PreparedStatement pstmt = null;
boolean re = false;
Conn conn = new Conn(connname);
try {
pstmt = conn.prepareStatement(INSERT);
pstmt.setString(1, nick);
pstmt.setString(2, link);
pstmt.setString(3, content);
pstmt.setString(4, ip);
pstmt.setInt(5, doc_id);
pstmt.setString(6, "" + System.currentTimeMillis());
id = (int)SequenceMgr.nextID(SequenceMgr.COMMENT);
pstmt.setLong(7, id);
re = conn.executePreUpdate()==1?true:false;
}
catch (SQLException e) {
logger.error(e.getMessage());
}
finally {
if (pstmt!=null) {
try {
pstmt.close();
}
catch (Exception e) {}
pstmt = null;
}
if (conn!=null) {
conn.close(); conn = null;
}
}
return re;
}
public String getContent() {
return content;
}
public String getIp() {
return ip;
}
public String getAddDate() {
return add_date;
}
public int getId() {
return id;
}
public String getNick() {
return nick;
}
public String getLink() {
return link;
}
public int getDocId() {
return doc_id;
}
public void load(int id) {
ResultSet rs = null;
PreparedStatement pstmt = null;
Conn conn = new Conn(connname);
try {
pstmt = conn.prepareStatement(LOAD);
pstmt.setInt(1, id);
rs = conn.executePreQuery();
if (rs!=null) {
if (rs.next()) {
id = rs.getInt(1);
nick = rs.getString(2);
content = rs.getString(3);
link = rs.getString(4);
ip = rs.getString(5);
java.util.Date d = DateUtil.parse(rs.getString(6));
add_date = DateUtil.format(d, "yyyy-MM-dd HH:mm:ss");
doc_id = rs.getInt(7);
}
}
}
catch (SQLException e) {
logger.error("load2" + e.getMessage());
}
finally {
if (rs!=null) {
try { rs.close(); } catch (Exception e) {}
rs = null;
}
if (pstmt!=null) {
try {
pstmt.close();
}
catch (Exception e) {}
pstmt = null;
}
if (conn!=null) {
conn.close(); conn = null;
}
}
}
public boolean del(int id) {
boolean re = true;
PreparedStatement pstmt = null;
Conn conn = new Conn(connname);
try {
pstmt = conn.prepareStatement(DEL);
pstmt.setInt(1, id);
re = conn.executePreUpdate()==1?true:false;
}
catch (SQLException e) {
re = false;
logger.error(e.getMessage());
}
finally {
if (pstmt!=null) {
try {
pstmt.close();
}
catch (Exception e) {}
pstmt = null;
}
if (conn!=null) {
conn.close(); conn = null;
}
}
return re;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -