QueryMails.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
- package com.softeem.webmail.dao.search;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import com.softeem.webmail.dao.DBManager;
- import com.softeem.webmail.dao.mail.Mail;
- public class QueryMails {
- private Connection conn;
-
- private PreparedStatement ps;
-
- private ResultSet rs;
-
- public List<Mail> queryMails(String sql){
- System.out.println(sql);
- conn = DBManager.getConnection();
- List<Mail> list = new ArrayList<Mail>();
- try {
- ps = conn.prepareStatement(sql);
- rs = ps.executeQuery();
- while(rs.next()){
- Mail mail = new Mail();
- mail.setId(rs.getInt("id"));
- mail.setAdds(rs.getString("adds"));
- mail.setBox_name(rs.getString("box_name"));
- mail.setContent(rs.getString("content"));
- mail.setDate(rs.getString("date"));
- mail.setMail_from(rs.getString("mail_from"));
- mail.setMail_to(rs.getString("mail_to"));
- mail.setSize(rs.getDouble("size"));
- mail.setStat(rs.getString("stat"));
- mail.setSubject(rs.getString("subject"));
- list.add(mail);
- }
- return list;
- } catch (SQLException e) {
- e.printStackTrace();
- }finally{
- DBManager.closeConnection(rs, ps, conn);
- }
- return null;
- }
- }