Questo è il mio codice:
mi da quest'errore:codice:package javaapplication7; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Date; import java.text.SimpleDateFormat; import javax.swing.JOptionPane; import javax.mail.*; import java.util.*; import javax.mail.internet.*; import javax.activation.*; import java.io.*; public class Controllo { private String cella=new String(); private String data_ita= new String(); private int contatore=0; private int cont=0; private String host = "smtp.gmail.com"; //tuo smtp private String from = mioindirizzio@gmail.it; //tuo indirizzo email private String ToAddress = "indirizzo del destinatario"; //destinatario private String user = ",mioindirizzo"; private String pass = "password"; public Controllo(){ // Indirizzo in cui si trova il database try { while (true) { Connection con = null; try { String driver = "net.sourceforge.jtds.jdbc.Driver"; Class.forName(driver).newInstance(); } catch (Exception e) { System.out.println("Fallito il caricamento dei driver SQL."); return; } try { String[] items = new String[30]; items[0]="Cella01Trend"; items[1]="Cella07Trend"; items[2]="Cella08Trend"; items[3]="Cella09Trend"; items[4]="Cella10Trend"; items[5]="Cella11Trend"; items[6]="Cella12Trend"; items[7]="Cella13Trend"; items[8]="Cella14Trend"; items[9]="Cella15Trend"; items[10]="Cella16Trend"; items[11]="Cella17Trend"; items[12]="Cella18Trend"; items[13]="Cella19Trend"; items[14]="Cella20Trend"; items[15]="Cella21Trend"; items[16]="Cella22Trend"; items[17]="Cella23ATrend"; items[18]="Cella23BTrend"; items[19]="Cella23CTrend"; items[20]="Cella24Trend"; items[21]="Cella25Trend"; items[22]="Cella26Trend"; items[23]="Cella27Trend"; items[24]="Cella28Trend"; items[25]="Cella30Trend"; items[26]="Cella31Trend"; items[27]="Cella32Trend"; items[28]="Cella33Trend"; items[29]="CellaRobotTrend"; for (int i=0;i<30;i++){ SimpleDateFormat giorno_form_db = new SimpleDateFormat( "yyyy/MM/dd" ); String data_attuale= new String(); data_attuale=giorno_form_db.format(new Date()); cella=items[i]; // Connessione col database in cui vengono specificati url, nome utente, password con = DriverManager.getConnection("jdbc:jtds:sqlserver://192.169.14.3:1433/Database", "**", "*"); Statement select = con.createStatement(); Statement select1 = con.createStatement(); //caricamento query SQL System.out.println(cella); ResultSet vuoto = select1.executeQuery("SELECT COUNT(*) FROM " +cella+ " where tempo>='" +data_attuale+"' and tempo<='" +data_attuale+ "%'"); while(vuoto.next()){ if((vuoto.getInt(1)==0)) { SimpleDateFormat giorno_ita = new SimpleDateFormat( "dd/MM/yyyy" ); data_ita=giorno_ita.format(new Date()); System.out.println(cella+ " non ha acquisito nessun dato in data " +data_ita); JOptionPane.showMessageDialog(null,cella+" non ha acquisito nessun dato in data "+data_ita,"ERRORE SCRITTURA DATI ODIERNI",JOptionPane.ERROR_MESSAGE); } else{ ResultSet ultimo_dato = select.executeQuery("SELECT TOP 1 * FROM " +cella+ " where tempo>='" +data_attuale+"' and tempo<='" +data_attuale+ "%'ORDER BY Tempo DESC"); while (ultimo_dato.next()) { java.util.Date orario_db = new SimpleDateFormat("yyyy/MM/dd HH.mm").parse(ultimo_dato.getString(2)); SimpleDateFormat or = new SimpleDateFormat("HH"); SimpleDateFormat min = new SimpleDateFormat("mm"); String ora_db=new String(); String ora_attuale=new String(); String min_db=new String(); String min_attuale=new String(); ora_attuale=or.format(new Date()); min_attuale=min.format(new Date()); ora_db=or.format(orario_db); min_db=min.format(orario_db); int ora_attuale_int=Integer.parseInt(ora_attuale); int min_attuale_int=Integer.parseInt(min_attuale); int ora_db_int=Integer.parseInt(ora_db); int min_db_int=Integer.parseInt(min_db); contatore=0; cont=0; if(ora_db_int==ora_attuale_int){ for(int j=0;j<10;j++){ if(min_db_int==min_attuale_int-j){ System.out.println("TUTTO OK"); contatore=1; } } if(contatore==0) { System.out.println(cella+ "KO"); javamail jv=new javamail(); JOptionPane.showMessageDialog(null,cella+" non ha salvato dati negli ultimi 10 minuti","ERRORE SCRITTURA DATABASE",JOptionPane.ERROR_MESSAGE); } } else{ if(ora_db_int==ora_attuale_int-1){ for(int w=59;w>49;w--){ if(min_db_int==w){ System.out.println("TUTTO OK"); cont=1; } } if(cont==0){ System.out.println(cella+ "KO"); JOptionPane.showMessageDialog(null,cella+" non ha salvato dati negli ultimi 10 minuti","ERRORE SCRITTURA DATABASE",JOptionPane.ERROR_MESSAGE); } } else { System.out.println(cella+ "KO"); JOptionPane.showMessageDialog(null,cella+" non ha salvato dati negli ultimi 10 minuti","ERRORE SCRITTURA DATABASE",JOptionPane.ERROR_MESSAGE); } } } } } } } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (Exception e) { e.printStackTrace(); } } } Thread.sleep (10*60*1000); // 10 minuti } }catch (Exception e) { e.printStackTrace(); } } public javamail() { try { //initialize the StringBuffer object within the try/catch loop StringBuffer sb = new StringBuffer( ); //Get system properties Properties props = System.getProperties( ); //Setup mail server props.put("mail.smtp.host", host); //props.put("mail.debug", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.auth","true"); //Get session Session session = Session.getDefaultInstance(props, null); //session.setDebug(true); session.setPasswordAuthentication(new URLName("smtp",host,25,"INBOX",user,pass), new PasswordAuthentication(user,pass)); //Define message MimeMessage msg = new MimeMessage(session); //Set the from address msg.setFrom(new InternetAddress(from)); //Set the to address msg.addRecipient(Message.RecipientType.TO, new InternetAddress(ToAddress)); //Oggetto della mail msg.setSubject("Cella Frigo non contiene dati corretti"); //Il corpo della mail sb.append(""); msg.setText(sb.toString( )); //Per inviare il messaggio Transport tr = session.getTransport("smtp"); tr.connect(host, user, pass); msg.saveChanges(); // don't forget this tr.sendMessage(msg, msg.getAllRecipients()); tr.close(); } catch (MessagingException e) { System.out.println(e); } } public static void main(String args[]) { Controllo c = new Controllo(); } }
D:\NetBeansProjects\JavaApplication7\src\javaappli cation7\Controllo.java:178: invalid method declaration; return type required
Come fare a risolvere....io al posto delle popup fatte con JOptionPane devo riuscire ad inviare una mail con dei dati presi da controllo tipo data attuale e ceel interessata...

Rispondi quotando