Fetch values from database and store it in array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sruthini
    New Member
    • Aug 2007
    • 25

    #16
    Hi,
    If I remove the quotes , I got the compile time error,

    cannot resolve symbol
    symbol:variable m
    location:messag e.setRecipient( Message.Recipie ntType.TO,new InternetAddress (m));


    [code=java]
    ArrayList list = new ArrayList();
    while(rs.next() )
    {
    String to=rs.getString (1);
    list.add(to);
    }
    String m="";
    for(int i=0;i<list.size ();i++)
    {
    m += list.get(i).toS tring();
    }
    MimeMessage message = new MimeMessage(ses sion);
    message.setReci pient(Message.R ecipientType.TO ,new InternetAddress (m));
    [/code]

    Please help me,

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #17
      Originally posted by sruthini
      cannot resolve symbol
      symbol:variable m
      location:messag e.setRecipient( Message.Recipie ntType.TO,new InternetAddress (m));
      ...
      [code=java]
      message.setReci pient(Message.R ecipientType.TO ,new InternetAddress (m));
      [/code]
      Why is it new InternetAddress (m) instead of new InternetAddress (to)? It doesn't recognize m! It used to be "to", didn't it?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by sruthini
        Hi,
        If I remove the quotes , I got the compile time error,

        cannot resolve symbol
        symbol:variable m
        location:messag e.setRecipient( Message.Recipie ntType.TO,new InternetAddress (m));


        [code=java]
        ArrayList list = new ArrayList();
        while(rs.next() )
        {
        String to=rs.getString (1);
        list.add(to);
        }
        String m="";
        for(int i=0;i<list.size ();i++)
        {
        m += list.get(i).toS tring();
        }
        MimeMessage message = new MimeMessage(ses sion);
        message.setReci pient(Message.R ecipientType.TO ,new InternetAddress (m));
        [/code]

        Please help me,
        But what you posted is not what your code looks like. Can you post the code that's giving you this error as it is?

        P.S It's not a bad time to read something about Java scoping rules.

        Comment

        • sruthini
          New Member
          • Aug 2007
          • 25

          #19
          Hi,

          I used the following code,
          [code=java]
          ArrayList list = new ArrayList();
          while(rs.next() )
          {
          //String to=rs.getString (1);
          list.add(rs.get String(1));
          }
          String m="";
          for(int i=0;i<list.size ();i++)
          {
          m += list.get(i).toS tring()+"," ;
          }
          //String to=m;



          MimeMessage message = new MimeMessage(ses sion);
          message.setReci pient(Message.R ecipientType.TO ,new InternetAddress (m));
          [/code]

          If I pass one mail id to database I got the correct answer, If I pass more than one mail ids , I got the following error,

          ERROR.....javax .mail.internet. AddressExceptio n: Illegal address in string ``dev@gmail.com ,anu@gmail.com, a@yaoo.com,b@ya hoo.com,''

          If I pass like

          message.setReci pient(Message.R ecipientType.TO ,new InternetAddress ("a@yaoo.com"," b@yahoo.com"));

          I got the correct answer, How to split the mail ids like above, If I use split(",") or "," means , It does not support more than one mail id's.

          Please give the solution.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Originally posted by sruthini
            Hi,

            I used the following code,
            [code=java]
            ArrayList list = new ArrayList();
            while(rs.next() )
            {
            //String to=rs.getString (1);
            list.add(rs.get String(1));
            }
            String m="";
            for(int i=0;i<list.size ();i++)
            {
            m += list.get(i).toS tring()+"," ;
            }
            //String to=m;



            MimeMessage message = new MimeMessage(ses sion);
            message.setReci pient(Message.R ecipientType.TO ,new InternetAddress (m));
            [/code]

            If I pass one mail id to database I got the correct answer, If I pass more than one mail ids , I got the following error,

            ERROR.....javax .mail.internet. AddressExceptio n: Illegal address in string ``dev@gmail.com ,anu@gmail.com, a@yaoo.com,b@ya hoo.com,''

            If I pass like

            message.setReci pient(Message.R ecipientType.TO ,new InternetAddress ("a@yaoo.com"," b@yahoo.com"));

            I got the correct answer, How to split the mail ids like above, If I use split(",") or "," means , It does not support more than one mail id's.

            Please give the solution.
            You can get an array of InternetAddress objects from using the parse method.

            Comment

            • sruthini
              New Member
              • Aug 2007
              • 25

              #21
              Hi,

              Thank you very much for your help, Now Its work perfectly with multiple mailid's.
              but In some other system its not working. my smtp settings like
              props.put("mail .smtp.host","ma il.companyname. com");

              If I give the mailids like a@company.com,b @company.com means
              its working proper, otherwise I give a@gmail.com,b@y ahoo.com means I got the following error,

              ERROR.....javax .mail.SendFaile dException: Invalid Addresses;
              nested exception is:
              class com.sun.mail.sm tp.SMTPAddressF ailedException: 500 Unauthorized relay msg rejected

              Please help me,

              thanks in advance.

              Comment

              Working...