类型Part中的方法setText(String)不适用于参数

时间:2012-12-29 04:54:54

标签: java string methods settext

我必须开发一个java应用程序。

我在这里得到以下错误:

类型Part中的方法setText(String)不适用于参数(String,String)

这里我必须通过settext将retrieveUserName,retrievePassword发送到我的邮箱。 如何在settext方法中调用上面的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("xxxxx@gmail.com","4242vfgDF!");
                        }
                    });
                   try {

            Message message = new MimeMessage(session);
             message.setFrom(new InternetAddress("krishnaveni.veeman@gmail.com"));
         message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("demo@gamil.com"));
            message.setSubject("Testing Subject");
            message.setText("Dear Friends This is your product name and price"+
                    retrievedPassword,retrievedUserName);

        Transport.send(message);

            System.out.println("Done");

            } 

1 个答案:

答案 0 :(得分:0)

尝试指定字符集。我也使用setContent,但我想setText会以同样的方式工作。尝试用以下代码替换你的setText调用:

 message.setContent("Dear Friends This is your product name and price "+
                     retrievedPassword+retrievedUserName, "text/html; charset=utf-8");