1
我必須開發一個Java應用程序。類型Part中的方法setText(String)不適用於參數
在這裏,我得到了以下錯誤:
在型部件的製備方法的setText(字符串)不適用的參數(字符串,字符串)
在這裏,我要送retrievedUserName, retrievePassword通過settext傳遞給我的郵件。 如何在settext method.please中調用上述2字符串值幫助我。在我的代碼中出現錯誤。
這是我的代碼:
public class SendMail {
public String authentication(String Product,String Cost){
String retrievedUserName = "";
String retrievedPassword = "";
String retrievedEmail = "";
String status = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT xcart_products.product,xcart_products.list_price,xcart_customers.email FROM xcart_products,xcart_customers WHERE product = '"+Product+"'");
ResultSet result = statement.executeQuery();
while(result.next()){
retrievedUserName = result.getString("list_price");
retrievedPassword = result.getString("product");
retrievedEmail = result.getString("email");
}
if(retrievedPassword.equals(Product)){
status = "The product name is send to your email";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
new PasswordAuthentication("[email protected]","4242vfgDF!");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Testing Subject");
message.setText("Dear Friends This is your product name and price"+
retrievedPassword,retrievedUserName);
Transport.send(message);
System.out.println("Done");
}
感謝danL.it是爲我工作。 – android
沒問題,很樂意幫忙。如果你不介意對我的答案進行投票,我將不勝感激。感謝你的接納! – SISYN
在使用setContent()時,不會產生「\ n」的效果。我必須需要fistline retrievePassword,必須需要第二行retrieveUserName.so我已經使用了下面的代碼。但它對我來說不起作用。 message.setContent(「這是你的產品名稱」+ retrievedPassword +「\ nThis is your price」+ retrieveUserName,「text/html; charset = utf-8」); – android