📄 dbreforum.java
字号:
package com.bwm.database;import java.sql.*;import java.util.*;import com.bwm.model.Reforum;import com.bwm.core.*;import com.jspsmart.upload.Request;/** * <p>Title: mingrisoft</p> * <p>Description: 明日科技门户网站</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: MR</p> * @author BWM * @version 1.0 */public class Dbreforum extends Reforum { private Reforum r=new Reforum(); public Dbreforum() { } public Dbreforum(String sql) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.SELECT_REFROUM + sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = ps.executeQuery(); if (rs.next()) { r.setRefid(rs.getInt("refid")); r.setFid(rs.getInt("fid")); r.setState(rs.getInt("state")); r.setIid(ParamUtils.getSqlString(rs.getString("iid"))); r.setContent(ParamUtils.getSqlString(rs.getString("content"))); r.setUid(ParamUtils.getSqlString(rs.getString("uid"))); r.setRtime(ParamUtils.getSqlString(rs.getString("rtime"))); } } catch (SQLException e) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { System.out.println(ps + " Dbreforum(String sql) " + FinalConstants.SELECT_REFROUM + sql); try { if (ps != null) { ps.close(); ps = null; } } catch (SQLException e) { ps = null; } try { if (con != null) { con.close(); con = null; } } catch (SQLException e) { con = null; } } } public Dbreforum(Request request,String iid) { r.setFid(ParamUtils.getIntParameter(request, "fid")); r.setState(ParamUtils.getIntParameter(request,"state")); r.setIid(ParamUtils.getSqlString(iid)); r.setContent(ParamUtils.getRequestString(request, "content")); r.setUid(ParamUtils.getRequestString(request, "uid")); r.setRtime(ParamUtils.getRequestString(request, "rtime")); } public boolean Insert() { boolean b = false; Connection con = null; PreparedStatement ps = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.INSERT_REFROUM); ps.setInt(1, r.getFid()); ps.setInt(2, r.getState()); ps.setString(3, r.getIid()); ps.setString(4, r.getContent()); ps.setString(5, r.getUid()); if (ps.executeUpdate() > 0) { b = true; } else { b = false; } } catch (SQLException e) { b = false; System.out.println(e.getMessage()); e.printStackTrace(); } finally { System.out.println(ps + " Dbreforum.Insert()"); try { if (ps != null) { ps.close(); } } catch (SQLException e) { ps = null; } try { if (con != null) { con.close(); } } catch (SQLException e) { con = null; } } return b; } public Collection Select(String sql) { Collection coll = new ArrayList(); Connection con = null; ResultSet rs = null; PreparedStatement ps = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.SELECT_REFROUM + sql); rs = ps.executeQuery(); while (rs.next()) { Reforum link = new Reforum(); link.setRefid(rs.getInt("refid")); link.setFid(rs.getInt("fid")); link.setState(rs.getInt("state")); link.setIid(ParamUtils.getSqlString(rs.getString("iid"))); link.setContent(ParamUtils.getSqlString(rs.getString("content"))); link.setUid(ParamUtils.getSqlString(rs.getString("uid"))); link.setRtime(ParamUtils.getSqlString(rs.getString("rtime"))); coll.add(link); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } finally { System.out.println(ps + " Dbreforum.Select(String sql) "); try { if (ps != null) { ps.close(); ps = null; } } catch (SQLException e) { ps = null; } try { if (con != null) { con.close(); con = null; } } catch (SQLException e) { con = null; } } return coll; } //页数+SQL条件 public Collection Select(int page, String sql) { Collection coll = new ArrayList(); Connection con = null; ResultSet rs = null; PreparedStatement ps = null; int tip = FinalConstants.STEP * (page - 1); try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.SELECT_REFROUM + sql); rs = ps.executeQuery(); if (tip <= 0) { rs.beforeFirst(); } else { if (!rs.absolute(tip)) { rs.beforeFirst(); } } for (int i = 1; rs.next() && i <= FinalConstants.STEP; i++) { Reforum link = new Reforum(); link.setRefid(rs.getInt("refid")); link.setFid(rs.getInt("fid")); link.setState(rs.getInt("state")); link.setIid(ParamUtils.getSqlString(rs.getString("iid"))); link.setContent(ParamUtils.getSqlString(rs.getString("content"))); link.setUid(ParamUtils.getSqlString(rs.getString("uid"))); link.setRtime(ParamUtils.getSqlString(rs.getString("rtime"))); coll.add(link); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } finally { System.out.println(ps + " Dbreforum.Select(int page,String sql) "); try { if (ps != null) { ps.close(); ps = null; } } catch (SQLException e) { ps = null; } try { if (con != null) { con.close(); con = null; } } catch (SQLException e) { con = null; } } return coll; } private boolean Update() { boolean b = false; Connection con = null; PreparedStatement ps = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.UPDATE_REFROUM); ps.setInt(1, r.getState()); ps.setString(2, r.getContent()); ps.setInt(3, r.getRefid()); if (ps.executeUpdate() > 0) { b = true; } else { b = false; } } catch (SQLException e) { b = false; e.printStackTrace(); } finally { System.out.println(ps + " Dbreforum.Update() "); try { if (ps != null) { ps.close(); } } catch (SQLException e) { ps = null; } try { if (con != null) { con.close(); } } catch (SQLException e) { con = null; } } return b; } public int getRefid() { return r.getRefid(); } public void setRefid(int refid) { r.setRefid(refid); } public int getFid() { return r.getFid(); } public void setFid(int fid) { r.setFid(fid); } public int getState() { return r.getState(); } public void setState(int state) { r.setState(state); this.Update(); } public String getIid() { return r.getIid(); } public void setIid(String iid) { r.setIid(iid); } public String getContent() { return r.getContent(); } public void setContent(String content) { r.setContent(content); this.Update(); } public String getUid() { return r.getUid(); } public void setUid(String uid) { r.setUid(uid); } public String getRtime() { return r.getRtime(); } public void setRtime(String rtime) { r.setRtime(rtime); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -