📄 dbfsort.java
字号:
package com.bwm.database;import java.sql.*;import java.util.*;import javax.servlet.http.HttpServletRequest;import com.bwm.model.Fsort;import com.bwm.core.*;/** * <p>Title: mingrisoft</p> * <p>Description: 明日科技门户网站</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: MR</p> * @author BWM * @version 1.0 */public class Dbfsort extends Fsort { private Fsort f=new Fsort(); public Dbfsort() { } public Dbfsort(String sql) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.SELECT_FSORT + sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = ps.executeQuery(); if (rs.next()) { f.setFsid(rs.getInt("fsid")); f.setState(rs.getInt("state")); f.setFree(rs.getInt("free")); f.setName(ParamUtils.getSqlString(rs.getString("name"))); f.setFtime(ParamUtils.getSqlString(rs.getString("ftime"))); f.setResume(ParamUtils.getSqlString(rs.getString("resume"))); f.setUid(ParamUtils.getSqlString(rs.getString("uid"))); } } catch (SQLException e) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { System.out.println(ps + " Dbfsort(String sql) " +FinalConstants.SELECT_FSORT + 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 Dbfsort(HttpServletRequest request) { f.setState(ParamUtils.getIntParameter(request, "state")); f.setFree(ParamUtils.getIntParameter(request, "free")); f.setName(ParamUtils.getRequestString(request, "name")); f.setResume(ParamUtils.getRequestString(request, "resume")); f.setUid(ParamUtils.getRequestString(request, "uid")); } public boolean Insert() { boolean b = false; Connection con = null; PreparedStatement ps = null; try { con = Database.getConnection(); ps = con.prepareStatement(FinalConstants.INSERT_FSORT); ps.setInt(1, f.getState()); ps.setInt(2, f.getFree()); ps.setString(3, f.getName()); ps.setString(4, f.getUid()); ps.setString(5, f.getResume()); 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 + " Dbfsort.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_FSORT + sql); rs = ps.executeQuery(); while (rs.next()) { Fsort link = new Fsort(); link.setFsid(rs.getInt("fsid")); link.setState(rs.getInt("state")); link.setFree(rs.getInt("free")); link.setName(ParamUtils.getSqlString(rs.getString("name"))); link.setFtime(ParamUtils.getSqlString(rs.getString("ftime"))); link.setResume(ParamUtils.getSqlString(rs.getString("resume"))); link.setUid(ParamUtils.getSqlString(rs.getString("uid"))); coll.add(link); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } finally { System.out.println(ps + " Dbfsort.Select(String sql) "+FinalConstants.SELECT_FSORT + 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_FSORT + 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++) { Fsort link = new Fsort(); link.setFsid(rs.getInt("fsid")); link.setState(rs.getInt("state")); link.setFree(rs.getInt("free")); link.setName(ParamUtils.getSqlString(rs.getString("name"))); link.setFtime(ParamUtils.getSqlString(rs.getString("ftime"))); link.setResume(ParamUtils.getSqlString(rs.getString("resume"))); link.setUid(ParamUtils.getSqlString(rs.getString("uid"))); coll.add(link); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } finally { System.out.println(ps + " Dbfsort.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_FSORT); ps.setInt(1, f.getState()); ps.setInt(2, f.getFree()); ps.setString(3, f.getName()); ps.setString(4, f.getUid()); ps.setString(5, f.getResume()); ps.setInt(6, f.getFsid()); if (ps.executeUpdate() > 0) { b = true; } else { b = false; } } catch (SQLException e) { b = false; e.printStackTrace(); } finally { System.out.println(ps + " Dbfsort.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 getState() { return f.getState(); } public void setState(int state) { f.setState(state); Update(); } public int getFsid() { return f.getFsid(); } public void setFsid(int fsid) { f.setFsid(fsid); } public String getName() { return f.getName(); } public void setName(String name) { f.setName(name); Update(); } public String getFtime() { return f.getFtime(); } public void setFtime(String ftime) { f.setFtime(ftime); } public String getUid() { return f.getUid(); } public void setUid(String uid) { f.setUid(uid); } public String getResume() { return f.getResume(); } public void setResume(String resume) { f.setResume(resume); Update(); } public int getFree() { return f.getFree(); } public void setFree(int free) { f.setFree(free); Update(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -