【问题标题】:Quartz Scheduler not inserting records in DB using JDBCStoreQuartz Scheduler 未使用 JDBCStore 在 DB 中插入记录
【发布时间】:2017-05-26 01:46:02
【问题描述】:

已配置的 Quartz 作业,

public static void schedule(IEntity entity, Date startdate) {
    try {
        JobDetail job = JobBuilder.newJob(StatingUpdateJob.class)
                .withIdentity("UpdateStagingRecords" + entity.getId(), "StgToProduction").build();
        JobDataMap data = new JobDataMap(new HashMap<>());
        data.put("Entity", entity);
        job.getJobBuilder().setJobData(data);

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        Date enddate = new Date();
        enddate.setTime(startdate.getTime() + 6000000);
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withIdentity("UpdateStagingRecords" + entity.getId(), "StgToProduction").startAt(startdate)
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/5 * 1/1 * ? *")
                        .withMisfireHandlingInstructionDoNothing())
                .endAt(enddate).build();
        Connection connection = DBConnectionManager.getInstance().getConnection("myDS");
        System.out.println(connection);
        scheduler.scheduleJob(job, cronTrigger);
        scheduler.start();
    } catch (Exception e) {
        System.out.println("Something went wrong");
        e.printStackTrace();
    }

}

然后将quartz.properties放到我的类路径中

org.quartz.scheduler.instanceName=JavacodeGeeksScheduler
org.quartz.scheduler.instanceId=99199
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=3
org.quartz.context.key.QuartzTopic=QuartzPorperties
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.dataSource=myDS
org.quartz.jobListener.NAME.class=com.javacodegeeks.quartz.MyJobListener
org.quartz.dataSource.myDS.driver=com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL=jdbc:mysql://localhost/test
org.quartz.dataSource.myDS.user=admin
org.quartz.dataSource.myDS.password=admin
org.quartz.dataSource.myDS.maxConnections=30

我的工作已成功创建并正确触发。但是,工作细节并没有放在数据库中。这是我的桌子

不确定我还需要配置什么。

【问题讨论】:

  • 在配置中最后5个属性用于定期检查配置文件,我不确定但你在用吗?如果没有,请尝试将它们注释掉。
  • @BilboBaggins 你的意思是数据源相关的东西?那是我们可以提供数据库详细信息的地方吗?不是吗?如果我错了,请纠正我
  • 不确定 MYSQL 的版本和选项,但它可能与大写问题有关。您的表格以小写 qrtz 开头,在您的配置中,您有这个 QRTZ_。
  • 是的,你是对的,我的错,我混淆了两个视图
  • @pringi 给我 2 分钟。我马上测试一下。

标签: java cron quartz-scheduler scheduler


【解决方案1】:

很奇怪,石英数据源 URL 不接受与本机 jdbc url 相同。

当我将 jdbc:mysql://localhost/test 更改为

jdbc:mysql://localhost:3306/test 

它成功了(感谢 @pringi@Bilbo Baggins)。

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多