我有一个连接到 SQL 数据库并从表中获取某些信息的类 (SQLRequests)。这些存储在结果集中(rsUpdate 和 rsNew)。下面是方法,我添加了一些代码以确保提取正确的数据。
public void ProcessSQLUpdate (Connection conn)
{
try
{
Statement stmt = conn.createStatement();
String sql = SQLDataAdaptor.SELECT_PROCESS_SQL_UPDATE;
ResultSet rsUpdate = stmt.executeQuery(sql);
while(rsUpdate.next ())
{
System.out.println("Applix Number: " + rsUpdate.getString(2) + " " + ("Change: " + rsUpdate.getString(1)));
logger.info("Applix Number: " + rsUpdate.getString(2) + " " + ("Change: " + rsUpdate.getString(1)));
}
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}
我想在不同类 (EmailSender) 的电子邮件方法中发送此信息,但我不知道如何将此信息添加到其中。
public void sendEmail () throws PollingException
{
Properties props = new Properties();
PollingProperties properties = PollingProperties.getInstance();
props.put("mail.smtp.host", (properties.getProperty(PollingProperties.POL_EMAIL_SMTP)));
Date date = new Date();
try {
Session mailSession = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(mailSession);
message.setSubject (properties.getProperty(PollingProperties.POL_EMAIL_SUBJECT));
message.setFrom(new InternetAddress(properties.getProperty(PollingProperties.POL_EMAIL_FROM)));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(properties.getProperty(PollingProperties.POL_EMAIL_TO)));
message.setText("Applix Update for " + date +
"\n\n New Rows: " [rsUpdate info here]+
"\n\n Updated Rows:");
Transport.send(message);
希望这是有道理的