Quartz Scheduler 不使用 JDBCStore 在数据库中插入记录
Quartz Scheduler not inserting records in DB using JDBCStore
已配置 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 放在我的 class 路径中
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
我的任务创建成功并正常触发。但是,工作细节并没有放在数据库中。这是我的表格
不确定我还需要配置什么。
奇怪的是,石英数据源 URL 不接受与原生 jdbc url 相同的数据源。
当我把jdbc:mysql://localhost/test
改成
的时候
jdbc:mysql://localhost:3306/test
成功了(感谢 @pringi 和 @Bilbo Baggins)。
已配置 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 放在我的 class 路径中
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
我的任务创建成功并正常触发。但是,工作细节并没有放在数据库中。这是我的表格
不确定我还需要配置什么。
奇怪的是,石英数据源 URL 不接受与原生 jdbc url 相同的数据源。
当我把jdbc:mysql://localhost/test
改成
jdbc:mysql://localhost:3306/test
成功了(感谢 @pringi 和 @Bilbo Baggins)。