www.pudn.com > Javamail.rar > GetMailList.java
package com.digipower.automail.mailsender; /** *Title:
*Description: TestStruts
*Copyright: Copyright (c) 2004
*Company: foxconn
* @author conti * @version 1.0 */ import java.sql.*; import javax.sql.*; import java.io.*; import java.util.*; import java.text.*; import com.digipower.common.basic.*; public class GetMailList { Connection conn = null; ConnectionDB_Oracle db = null; Statement stmt = null; ResultSet rst = null; PreparedStatement myPrepStatement = null; public GetMailList() throws Exception { db = new ConnectionDB_Oracle(); conn = db.getConnection(); } public Collection getFolderName() throws Exception { Collection ret = new ArrayList(); try { stmt = conn.createStatement(); String sql = "select * from AutoMail_Master where IsSend = 'N'"; rst = stmt.executeQuery(sql); while (rst.next()) { String item = rst.getString("FolderNameM"); ret.add(item); } } catch(Exception e) { e.printStackTrace(); } finally { try { if (stmt!=null) {stmt.close();} if (rst != null) {rst.close();} } catch(Exception e) { e.printStackTrace(); } return ret; } // return ret; } public Collection getSubject() throws Exception { Collection ret = new ArrayList(); try { Statement stmt = conn.createStatement(); String sql = "select * from AutoMail_Master where IsSend = 'N'"; ResultSet rst = stmt.executeQuery(sql); while (rst.next()) { String item = rst.getString("Subject"); ret.add(item); } } catch(Exception e) { e.printStackTrace(); } finally { try { if (stmt!=null) {stmt.close();} if (rst != null) {rst.close();} } catch(Exception e) { e.printStackTrace(); } } return ret; } public Collection getReply() throws Exception { Collection ret = new ArrayList(); try { stmt = conn.createStatement(); String sql = "select * from AutoMail_Master where IsSend = 'N'"; rst = stmt.executeQuery(sql); while (rst.next()) { String item = rst.getString("IsReply"); ret.add(item); } } catch(Exception e) { e.printStackTrace(); } finally { try { if (stmt!=null) {stmt.close();} if (rst != null) {rst.close();} } catch(Exception e) { e.printStackTrace(); } return ret; } } public void sendOver(String folderNameM) throws Exception { try { String sql = "update AutoMail_Master set IsSend = ? where FolderNameM = ?"; conn.setAutoCommit(false); myPrepStatement = conn.prepareStatement(sql); myPrepStatement.setString(1, "Y"); myPrepStatement.setString(2, folderNameM); myPrepStatement.executeUpdate(); conn.commit(); } catch(Exception e) { if(conn != null) {conn.rollback();} e.printStackTrace(); } finally { try { if(myPrepStatement != null) myPrepStatement.close(); } catch (Exception e) { e.printStackTrace(); } } } public void setMailDate(String folderNameM) throws Exception { try { java.util.Date nowDate = new java.util.Date(); Format formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String s = formatter.format(nowDate); java.util.Date g = new java.util.Date(s); String sql = "update AutoMail_Master set MailDate = ? where FolderNameM = ?"; conn.setAutoCommit(false); myPrepStatement = conn.prepareStatement(sql); myPrepStatement.setTimestamp(1,new java.sql.Timestamp(g.getTime())); myPrepStatement.setString(2, folderNameM); myPrepStatement.executeUpdate(); conn.commit(); } catch(Exception e) { if(conn != null) { conn.rollback(); } e.printStackTrace(); } finally { try { if(myPrepStatement != null) { myPrepStatement.close(); } } catch (Exception e) { e.printStackTrace(); } } } public void disconn() throws Exception { System.out.println("disconn"); if (conn != null) conn.close(); } }