我有一個類(SQLRequests),它連接到SQL數據庫並從表中獲取某些信息。這些存儲在結果集(rsUpdate和rsNew)中。下面是方法,我添加了一些代碼以確保正確的數據被抽出。在另一個類java中訪問resultSet中的數據
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);
希望是有道理的
格式的代碼正確 – exexzian
你要什麼派?您可以將必要的數據作爲參數發送到相關方法,也許是一個Map! – NINCOMPOOP