Ir para conteúdo
Fórum Script Brasil
  • 0

Duvida java + pl-sql oracle


Charles Ubiratan Kostetzer

Pergunta

Boa tarde, estou iniciando em java, e está me gerando um erro ao criar a um java source:

MAIL:72: warning: finally clause cannot complete normally
        }                                                
        ^                                                
1 warning                                                
 

Por favor onde estou errando ?


create or replace and compile java source named mail as
import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.Date;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

public class mail {
    static String dftMime = "application/octet-stream";
    static String dftName = "filename.dat";

    public static oracle.sql.NUMBER send(String from,
                                         String to,
                                         String cc,
                                         String bcc,
                                         String subject,
                                         String body,
                                         String SMTPHost,
                                         oracle.sql.BLOB attachmentData,
                                         String attachmentType,
                                         String attachmentFileName) {
        int rc = 0;
        try {
            Properties props = System.getProperties();
            props.put("mail.smtp.host", SMTPHost);
            Message msg = new MimeMessage(Session.getDefaultInstance(props, null));
            msg.setFrom(new InternetAddress(from));

            if (to != null )    
                msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));

            if (cc != null)     
                msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false));

            if (bcc != null)     
                msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false));

            if (subject != null)      
                msg.setSubject(subject);
            else
                msg.setSubject("(no subject)");

            msg.setSentDate(new Date());

            if (attachmentData != null) {
                MimeBodyPart mbp1 = new MimeBodyPart();
                mbp1.setText((body != null ? body : ""));
                mbp1.setDisposition(Part.INLINE);
                MimeBodyPart mbp2 = new MimeBodyPart();
                String type = (attachmentType != null ? attachmentType : dftMime);
                String fileName = (attachmentFileName != null ? attachmentFileName : dftName);
                mbp2.setDisposition(Part.ATTACHMENT);
                mbp2.setFileName(fileName);
                mbp2.setDataHandler(new DataHandler(new BLOBDataSource(attachmentData, type)));
                MimeMultipart mp = new MimeMultipart();
                mp.addBodyPart(mbp1);
                mp.addBodyPart(mbp2);
                msg.setContent(mp);
            } else {
                msg.setText((body != null ? body : ""));
            }
            Transport.send(msg);
            rc = 1;
        } catch (Exception e) {
            e.printStackTrace();
            rc = 0;
        } finally {
            return new oracle.sql.NUMBER(rc);
        }
    }


    static class BLOBDataSource implements DataSource {
        private BLOB   data;
        private String type;

        BLOBDataSource(BLOB data, String type) {
            this.type = type;
            this.data = data;
        }

        public InputStream getInputStream() throws IOException {
            try {
                if(data == null)
                    throw new IOException("No data.");

                return data.getBinaryStream();
            } catch(SQLException e) {
                throw new IOException("Cannot get binary input stream from BLOB.");
            }
        }

        public OutputStream getOutputStream() throws IOException {
            throw new IOException("Cannot do this.");
        }

        public String getContentType() {
            return type;
        }

        public String getName() {
            return "BLOBDataSource";
        }
    }
}

 

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...