MailDAO.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:2k
- package com.softeem.webmail.dao.mail;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.List;
- import com.softeem.ibatis3.DAOSupport;
- import com.softeem.ibatis3.IbatisSqlMapSessionFactory;
- import com.softeem.webmail.dao.DBManager;
- public class MailDAO extends DAOSupport {
-
- public static List<Mail> getMailsByUsername(String username){
- // System.out.println("----");
- try {
- List mails=getTemplate().queryForList("getMailsByName", username);
- IbatisSqlMapSessionFactory.coloseClient();
- IbatisSqlMapSessionFactory.coloseSqlMapSession();
- return mails;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static Mail getMailById(int id){
- try {
- return (Mail) getTemplate().queryForObject("selectMailById", id);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
-
-
- }
-
- public static void insertMail(Mail mail){
- try {
- getTemplate().insert("inserMail", mail);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- public static void deleteMail(int id){
- try {
- getTemplate().delete("DeleteMailById", id);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public static int getMailNumber(String username){
- int count=0;
- Connection conn= DBManager.getConnection();
- String sql="select * from mail where mail_to=? and stat='1'";
- try {
- PreparedStatement ps=conn.prepareStatement(sql);
- ps.setString(1,username);
- ResultSet rs=ps.executeQuery();
- while(rs.next()){
- count++;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return count;
- }
-
- public static void main(String[] args) {
- // IbatisSqlMapSessionFactory.getSqlMapSession();
- // IbatisSqlMapSessionFactory.coloseClient();
- // IbatisSqlMapSessionFactory.coloseSqlMapSession();
- // IbatisSqlMapSessionFactory.getSqlMapSession();
- MailDAO dao=new MailDAO();
- Mail mail=dao.getMailById(5);
- System.out.println(mail);
- // List lists=dao.getMailsByUsername("sad");
- // System.out.println(lists.size());
- // System.out.println(MailDAO.getMailsByUsername("sad").size()+"---");
- }
- }