messagedb.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 261 行
JAVA
261 行
package cn.js.fan.module.guestbook;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.redmoon.forum.*;public class MessageDb extends ObjectDb { String connname = Global.defaultDB; String userName; private String reply; String ip; int id; public MessageDb() { super(); } public MessageDb(int id) { this.id = id; load(); init(); } public int getId() { return id; } public String getContent() { return content; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public String getUserName() { return userName; } public java.util.Date getDate() { return lydate; } public String getReply() { return reply; } public String getShopCode() { return shopCode; } public java.util.Date getLydate() { return lydate; } public java.util.Date getRedate() { return redate; } public boolean isScret() { return scret; } public java.util.Date getReDate() { return redate; } public void initDB() { this.tableName = "guestbook"; primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT); objectCache = new MessageCache(this); this.QUERY_DEL = "delete FROM guestbook WHERE id=?"; this.QUERY_CREATE = "INSERT INTO guestbook (content, userName, ip, lydate, shopCode, id, is_scret) VALUES (?,?,?,?,?,?,?)"; this.QUERY_LOAD = "SELECT id, content, userName, ip, lydate, reply, redate, shopCode, is_scret FROM guestbook WHERE id=?"; this.QUERY_SAVE = "UPDATE guestbook SET content=?, reply=?, redate=?, is_scret=? WHERE id=?"; isInitFromConfigDB = false; } public boolean save() throws ErrMsgException { Conn conn = new Conn(connname); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(this.QUERY_SAVE); pstmt.setString(1, content); pstmt.setString(2, reply); pstmt.setTimestamp(3, new Timestamp(new java.util.Date().getTime())); pstmt.setInt(4, scret?1:0); pstmt.setInt(5, id); if (conn.executePreUpdate() == 1) { MessageCache mc = new MessageCache(this); primaryKey.setValue(new Integer(id)); mc.refreshSave(primaryKey); return true; } else return false; } catch (SQLException e) { logger.error(e.getMessage()); throw new ErrMsgException("更新留言出错!"); } finally { if (conn != null) { conn.close(); conn = null; } } } public void load() { Conn conn = new Conn(connname); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = conn.prepareStatement(this.QUERY_LOAD); pstmt.setInt(1, id); rs = conn.executePreQuery(); if (rs.next()) { this.id = rs.getInt(1); this.content = rs.getString(2); this.userName = rs.getString(3); this.ip = rs.getString(4); lydate = DateUtil.parse(rs.getString(5)); this.reply = StrUtil.getNullString(rs.getString(6)); redate = rs.getTimestamp(7); shopCode = rs.getString(8); scret = rs.getInt(9)==1; primaryKey.setValue(new Integer(id)); loaded = true; } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } } public boolean del() throws ErrMsgException { Conn conn = null; ResultSet rs = null; try { conn = new Conn(connname); PreparedStatement pstmt = conn.prepareStatement(this.QUERY_DEL); pstmt.setInt(1, id); if (conn.executePreUpdate()==1) { MessageCache mc = new MessageCache(this); primaryKey.setValue(new Integer(id)); mc.refreshDel(primaryKey); return true; } else return false; } catch (SQLException e) { logger.error("del:" + e.getMessage()); throw new ErrMsgException("删除出错!"); } finally { if (conn != null) { conn.close(); conn = null; } } } public boolean create() throws ErrMsgException { Conn conn = null; ResultSet rs = null; try { conn = new Conn(connname); PreparedStatement pstmt = conn.prepareStatement(this.QUERY_CREATE); pstmt.setString(1, content); pstmt.setString(2, userName); pstmt.setString(3, ip); pstmt.setString(4, "" + System.currentTimeMillis()); pstmt.setString(5, shopCode); id = (int)SequenceMgr.nextID(SequenceMgr.GUESTBOOK); pstmt.setInt(6, id); pstmt.setInt(7, scret?1:0); conn.executePreUpdate(); MessageCache mc = new MessageCache(this); mc.refreshCreate(); } catch (SQLException e) { logger.error("create:" + e.getMessage()); throw new ErrMsgException("插入留言出错!"); } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public MessageDb getMessageDb(int id) { return (MessageDb)getObjectDb(new Integer(id)); } public void setUserName(String userName) { this.userName = userName; } public void setContent(String content) { this.content = content; } public void setReply(String reply) { this.reply = reply; } public void setShopCode(String shopCode) { this.shopCode = shopCode; } public void setScret(boolean scret) { this.scret = scret; } public void setLydate(Date lydate) { this.lydate = lydate; } public void setRedate(Date redate) { this.redate = redate; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new MessageDb(pk.getIntValue()); } private String content; private String shopCode = "default"; private java.util.Date lydate; private java.util.Date redate; private boolean scret = false;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?