4
Guys how do I take the Infinite Loop out of this class? Every time it is the last database information he keeps sending email.
public class Dia06 {
public static final long TEMPO = (14 * 1440);
protected static final String Class = null;
public static void main(String[] args) throws SQLException {
Connection conexao = new Conexao().getConnection();
PreparedStatement stmt = conexao.prepareStatement(
"SELECT P.duplic, "
+ " P.dtemissao, "
+ " P.dtvenc, "
+ " P.valor, "
+ " C.cliente, "
+ " P.obs2, "
+ " c.email, "
+ " P.codcli, "
+ " C.telent, "
+ " Nvl(P.valordesc, 0) VLDESC, "
+ " P.codusur, "
+ " P.prest, "
+ " P.codcob, "
+ " C.ieent, "
+ " C.bloqueio, "
+ " P.duplic "
+ " || '-' "
+ " || P.prest AS TITULO, "
+ " P.numtransvenda, "
+ " P.codfilial "
+ "FROM pcprest P, "
+ " pcclient C, "
+ " pccob B, "
+ " pcfilial F "
+ "WHERE P.codcob = B.codcob "
+ " AND P.codcli = C.codcli "
+ " AND P.codfilial = F.codigo "
+ " AND F.CODIGO = 3 "
+ " AND p.codcob NOT IN ( 'DEVP', 'DEVT', 'BNF', 'BNFT', "
+ " 'BNFR', 'BNTR', 'BNRP', 'CRED', 'DESD' ) "
+ " AND P.dtpag IS NULL "
+ " AND p.dtvenc = To_date(SYSDATE)-6");
ResultSet rs = stmt.executeQuery();
while (rs.next()){
final String cliente = rs.getString("cliente");
final String dtvenc = rs.getString("dtvenc");
final String valor = rs.getString("valor");
//final String EMAIL = rs.getString("EMAIL");
//final String duplic = rs.getString("duplic");
Timer timer = null;
if (timer == null) {
timer = new Timer();
TimerTask tarefa = new TimerTask() {
@SuppressWarnings("deprecation")
public void run() {
//criar um update depois que enviar o email.
try {
MultiPartEmail emai = new MultiPartEmail(); //classe utilizada para permitir anexos no email
emai.setDebug(true);
emai.setHostName("192.168.2.200"); //servidor SMTP. Aqui usamos um do Gmail
emai.setSmtpPort(25);
emai.setAuthentication("[email protected]", "898999"); // login e senha da conta Gmail
emai.setSSL(false); //Autentica��o de seguran�a SSL setada como True
//emai.addTo(EMAIL);
emai.addTo("[email protected]"); //nome do email que vai receber o bkp do banco de dados. Pode ser o seu para teste
emai.setFrom("[email protected]"); //endere�o de email do remetente
emai.setSubject("Cobran�a de D�vida Ativa"); //assunto
emai.setMsg("Prezado( a ) Senhor( a ): " + cliente
+"Prezados,\n\n"
+" Conforme descrito no comunicado emitido anteriormente, informamos que, em virtude do n�o pagamento do t�tulo do t�tulo tal,\n "
+" com vencimento para "+dtvenc+", no valor de R$"+valor+", o(s) mesmo(s) ser�(�o) levado(s) a protesto, e os dados de v. senhoria\n "
+" inscritos nos cadastros de restri��o ao cr�dito.\n\n"
+"
+"Certos de sua compreens�o, mantemo-nos � disposi��o para a resolu��o desta pend�ncia. \n\n"
+"Por tratar-se de aviso autom�tico enviado eletronicamente, para o caso do referido pagamento j� ter sido efetuado, pe�o que entrem \n"
+"em contato para normaliza��o da situa��o descrita. \n\n"
+"Bras�lia-DF, xx de Xxxxxxxx de 2014. \n\n"
+"Atenciosamente, \n\n"); //carta03
emai.send(); //envia o email
} catch (EmailException e) { //exception caso aconte�a algum erro ao enviar o email
e.printStackTrace() ;
//chamar metodo
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("saida 1");
}
};
timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);
}
}
}
`
from what I can tell you’re using thread...try to stop using task.();
– Pedro Rangel
Thanks Peter for the answer more where should I put? I tried before I could not, sorry the ignorance more I’m beginner in the area.
– Wesley Costa
tries to put after emai.send();
– Pedro Rangel
ta printing "output 1"?
– Pedro Rangel
Pedro didn’t work out, he’s making a mistake.
– Wesley Costa
yes you are leaving
saida 1
– Wesley Costa
blz then.. when finished do not call the scheduleAtFixedRate method, as it will repeat the execution .
– Pedro Rangel
more with the scheduleAtFixedRate method it does the time count to send the letter!!! or to wrong?
– Wesley Costa
after System.out.println("output 1"); use (timer.Cancel(); and timer.purge();) or System.Exit(0); see this link... http://www.dsc.ufcg.edu.br/~Jacques/courses/map/html/threads/timer.html
– Pedro Rangel
see my answer to see if it helps you.
– Pedro Rangel
to help and be helped when necessary^^
– Pedro Rangel