title: QuartzScheduler: Send error messages to different reports at different time periods
body: <p>I'm using quartz scheduler to send error messages to different reports at different time periods. I have created one scheduler that runs every hour which will execute the second scheduler (the code shown here). The time at which the message must be sent is got from the database and that is passed in the exp variable. I'm able to fetch the value of only the first row in the database and am also getting a <strong><em>org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'q3Job.cronJob3', because one already exists with this identification.</em></strong>' error. How to correct this error? Could anyone suggest me the right way to approach this <strong><em>task of scheduling</em></strong>?</p>
  
  <p><strong>QSchedule2 Class</strong></p>
  
  <pre><code>public class QSchedule2 implements Job {
  
      private static Date date1 = null;
      private static Date date2 = null;
  
      private static String dateStart = "";
      private static String dateStop = "";
  
      public void execute(JobExecutionContext context) throws JobExecutionException {
          q2();
      }
  
      public void q2() {
          String exp = "";
          try {
              Class.forName(driverClassName);
              con = DriverManager.getConnection(url, dbUsername, dbPassword);
  
              dateStop = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(System.currentTimeMillis());
  
              ps = con.prepareStatement(
                      "select report_name,frequency,emailDate from ErrorReport where sendReport='Yes'");
              rs = ps.executeQuery();
  
              while (rs.next()) {
  
                  dateStart = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(rs.getTimestamp(3));
  
                  SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
  
                  date1 = format.parse(dateStart);
                  date2 = format.parse(dateStop);
  
                  long diff = date2.getTime() - date1.getTime();
  
                  long diffMinutes = diff / (60 * 1000) % 60;
  
                  String frequency = rs.getString(2);
                  int freq = Integer.parseInt(frequency);
  
                  if (diffMinutes &gt;= freq) {
                      exp = "0 0/" + freq + " * 1/1 * ? *";
  
                      Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
  
                      JobDetail job = newJob(Q3.class).withIdentity("cronJob", "q3Job").build();
  
                      CronTrigger cronTrigger = newTrigger().withIdentity("trigger1", "q3Job")
                              .withSchedule(CronScheduleBuilder.cronSchedule(exp)).build();
  
                      scheduler.scheduleJob(job, cronTrigger);
                      scheduler.start();
                  } else {
                      System.err.println("No email sent");
                  }
  
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
              try {
                  rs.close();
                  ps.close();
                  con.close();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>