📄 emailmanager.java
字号:
/* * EmailManager.java * * Created on 2002年2月20日, 上午11:36 */package com.gs.email;import com.gs.db.*;import com.gs.util.*;import com.gs.db.util.*;import java.util.*;import java.lang.*;import java.util.Date;import java.sql.*;import com.gs.db.dbimp.*;/** * * @author Administrator * @version */public class EmailManager { Authorization authorization; IofficePermissions permissions; private static final String GET_DETAIL = "select * from emaildetail order by emailtime desc"; private static final String GET_DETAIL1 = "select * from emaildetail where id = ? order by emailtime desc"; private static final String GET_DETAIL2 = "select * from emaildetail where emailtime >= ? and emailtime <= ? order by emailtime desc"; private static final String GET_DETAIL3 = "select * from emaildetail where userid = ? order by emailtime desc"; private static final String DELETE_DETAIL = "delete from emaildetail where id = ?"; Email email = null; /** Creates new EmailManager */ public EmailManager(Authorization authorization,IofficePermissions permissions) { this.authorization = authorization; this.permissions = permissions; } public Email addDetail(int userid,long emailtime,String content,String detail) { return new Email(userid,emailtime,content,detail); } public Email getEmail(int id) { Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(GET_DETAIL1); pstmt.setInt(1,id); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { email = new Email(rs.getInt(1),rs.getInt(2),rs.getLong(3),rs.getString(4),rs.getString(5)); } } catch( SQLException sqle ) { sqle.printStackTrace(); return null; } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } return email; } public ArrayList getEmails() { Connection con = null; PreparedStatement pstmt = null; ArrayList list = new ArrayList(); try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(GET_DETAIL); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { email = new Email(rs.getInt(1),rs.getInt(2),rs.getLong(3),rs.getString(4),rs.getString(5)); list.add(email); } } catch( SQLException sqle ) { sqle.printStackTrace(); return null; } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } public ArrayList getEmailsByUser(int userid) { Connection con = null; PreparedStatement pstmt = null; ArrayList list = new ArrayList(); try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(GET_DETAIL3); pstmt.setInt(1,userid); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { email = new Email(rs.getInt(1),rs.getInt(2),rs.getLong(3),rs.getString(4),rs.getString(5)); list.add(email); } } catch( SQLException sqle ) { sqle.printStackTrace(); return null; } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } public ArrayList getEmailsByTime(long start,long end) { Connection con = null; PreparedStatement pstmt = null; ArrayList list = new ArrayList(); try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(GET_DETAIL2); pstmt.setLong(1,start); pstmt.setLong(2,end); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { email = new Email(rs.getInt(1),rs.getInt(2),rs.getLong(3),rs.getString(4),rs.getString(5)); list.add(email); } } catch( SQLException sqle ) { sqle.printStackTrace(); return null; } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } public void deleteEmail(int id) { Connection con = null; PreparedStatement pstmt = null; try{ con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(DELETE_DETAIL); pstmt.setInt(1,id); pstmt.executeUpdate(); } catch(SQLException sqle){ sqle.printStackTrace(); } finally{ try { pstmt.close(); } catch (Exception e) {e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -