Quartz作业调度定时完成数据库操作
2015-07-21 09:45
281 查看
public class QuartzTest {
public static void main(String args[]) throws SchedulerException, ParseException {
JobDetail jobDetail= JobBuilder.newJob(TestJob.class)
.withIdentity("testJob_1","group_1")
.build();
Trigger trigger= TriggerBuilder
.newTrigger()
.withIdentity("trigger_1","group_1")
.startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInHours(24) //时间间隔24小时
.withRepeatCount(3) //重复次数(将执行4次)
)
.build();
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
sched.scheduleJob(jobDetail,trigger);
sched.start();
}
}
TestJob.java
public class TestJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("-------Hello World! ------" + new Date());
//do more...
Connection connection = null;
PreparedStatement ps=null;
ResultSet rs = null;
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/emsprodb", "postgres",
"123");
ps = connection.prepareStatement("select * from worktastcreate()");
rs = ps.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
}
postgresql的worktastcreate()语句:
CREATE OR REPLACE FUNCTION worktastcreate()
RETURNS integer AS
$BODY$
begin
INSERT INTO work_task(
code, name_en, name_cn, create_by, update_by, create_datetime,
update_datetime, version, spec_code, incharge, assign_by, priority,
factory_code, location_code) values('ad', 'cn', 'en','rao','rao', now(),
now(), 1, 'xx', 'xx', 'xx', 1,
'xx', 'xx');
return 0;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION worktastcreate()
OWNER TO postgres;
public static void main(String args[]) throws SchedulerException, ParseException {
JobDetail jobDetail= JobBuilder.newJob(TestJob.class)
.withIdentity("testJob_1","group_1")
.build();
Trigger trigger= TriggerBuilder
.newTrigger()
.withIdentity("trigger_1","group_1")
.startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInHours(24) //时间间隔24小时
.withRepeatCount(3) //重复次数(将执行4次)
)
.build();
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
sched.scheduleJob(jobDetail,trigger);
sched.start();
}
}
TestJob.java
public class TestJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("-------Hello World! ------" + new Date());
//do more...
Connection connection = null;
PreparedStatement ps=null;
ResultSet rs = null;
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/emsprodb", "postgres",
"123");
ps = connection.prepareStatement("select * from worktastcreate()");
rs = ps.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
}
postgresql的worktastcreate()语句:
CREATE OR REPLACE FUNCTION worktastcreate()
RETURNS integer AS
$BODY$
begin
INSERT INTO work_task(
code, name_en, name_cn, create_by, update_by, create_datetime,
update_datetime, version, spec_code, incharge, assign_by, priority,
factory_code, location_code) values('ad', 'cn', 'en','rao','rao', now(),
now(), 1, 'xx', 'xx', 'xx', 1,
'xx', 'xx');
return 0;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION worktastcreate()
OWNER TO postgres;
相关文章推荐
- java定时调度器(Quartz)使用实例
- quartz实现定时功能实例详解(servlet定时器配置方法)
- Spring3.2.0和Quartz1.8.6集群配置
- JFinal 整合Quartz
- JFinal Quartz 支持配置文件和持久化
- quartz的简单实现
- jfinal-quartz 使用jfinal启动quartz执行定时任务
- spring任务实时调度的几个方法
- Quartz Core 图层编程
- spirng-quartz定时任务简单实用
- iOS开发 — Quartz 2D基本使用
- iOS开发 — Quartz 2D知识点应用 (制作了一个Demo,源代码)
- Xcode Quartz 2D 绘图
- Spring Quartz定时任务不准时执行
- spring quartz 线程调度服务
- Spring Quartz的cron表达式
- CRON表达式详解
- Quartz定时器时间格式设置
- quartz使用
- Spring Quartz任务调度