当前正在一个项目中,其中将在Java Mail API主体中设置我的DataRetrival
类。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
//import com.mysql.jdbc.Statement;
public class DataRetrival {
public List<Employee> javaData() {
DatabaseConnect dc = new DatabaseConnect();
Connection con;
List<Employee> employees = new ArrayList<>();
try {
con = dc.connect();
String query ="SELECT * FROM employee";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
Employee emp = new Employee();
emp.setID(rs.getInt("ID"));
emp.setEmployee_Number(rs.getString("Employee_Number"));
emp.setFirstName(rs.getString("FirstName"));
emp.setLastName(rs.getString("LastName"));
emp.setEmailAddress(rs.getString("EmailAddress"));
emp.setPdfName(rs.getString("PdfName"));
emp.setEmailAddress(rs.getString("Sup_EmailAddress"));
employees.add(emp);
String employeeNumber = rs.getString("Employee_Number");
System.out.println(employeeNumber);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return employees;
}
创建了这样的新实例。
DataRetrival dtr = new DataRetrival();
从这个新实例或任何其他方法中,我想填充 InterenetAddress.parse 字段,其中包含名为 JavaMail 的另一个类,其中上面的字段代码段中提到的EmailAddress ;
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(Want get called Email_Adress));
答案 0 :(得分:1)
来自comment:
我想调用javaData()并将getEmailAddress获取到另一个类
呼叫javaData()
:
DataRetrival dtr = new DataRetrival();
List<Employee> employees = dtr.javaData();
要获取getEmailAddress
:
for (Employee employee : employees) {
String emailAddress = employee.getEmailAddress();
// use value here
}
以上两种构造都是Java的核心功能,因此,建议您重新阅读how to do method calls和how to iterate a list上的Java指南。