Quartz JDBCJobstore 不起作用

发布于 2024-07-30 01:32:24 字数 4774 浏览 2 评论 0原文

我已经下载了 Quartz 并且正在尝试运行示例。

我有一个使用 JDBCJobStore 的示例,该示例不起作用,但该示例与 RAMJobStore 一起工作正常。

就在我选择 JDBCJobStore 并引发异常时。

我使用的是quartz-1.6.5。

代码:

package test;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;



public class ReportRunner {
    public static void main(String[] args) {
        try {

            SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
            Scheduler sched = schedFact.getScheduler();
            sched.start();

            JobDetail jobDetail = null;
            SimpleTrigger trigger2 = null;

            jobDetail = new JobDetail("Income Report", "Report Generation",
                    QuartzReport.class);
            jobDetail.getJobDataMap().put("type", "FULL");
            jobDetail.setDurability(true);

            trigger2 = new SimpleTrigger("Income Report", "Report Generation");

            trigger2.setStartTime(new java.util.Date(
                    System.currentTimeMillis() + 4000));
            trigger2.setRepeatInterval(5000);
            trigger2.setRepeatCount(100);
            sched.scheduleJob(jobDetail, trigger2);



        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

package test;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class QuartzReport implements Job {

    public void execute(JobExecutionContext cntxt) throws JobExecutionException {
        System.out.println("Generating report - "
                + cntxt.getJobDetail().getJobDataMap().get("type"));

    }
}

配置文件:

org.quartz.scheduler.instanceName = Sched1
org.quartz.scheduler.instanceId = 1
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.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.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://192.168.0.4:3306/conference
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password =root
org.quartz.dataSource.myDS.maxConnections 5 

这是运行时显示的例外,已记录


org.quartz.JobPersistenceException: Couldn't acquire next trigger: Field 'PRIORITY' doesn't have a default value [See nested exception: java.sql.SQLException: Field 'PRIORITY' doesn't have a default value]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:1778)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.acquireNextTrigger(JobStoreTX.java:1218)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:233)
* Nested Exception (Underlying Cause) ---------------
java.sql.SQLException: Field 'PRIORITY' doesn't have a default value
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.insertFiredTrigger(StdJDBCDelegate.java:3360)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:1771)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.acquireNextTrigger(JobStoreTX.java:1218)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:233)
547  [QuartzScheduler_MyClusteredScheduler-NON_CLUSTERED_MisfireHandler] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore  - Lock 'TRIGGER_ACCESS' retuned by: QuartzScheduler_MyClusteredScheduler-NON_CLUSTERED_MisfireHandler

I have downloaded Quartz and I am trying to run a sample.

I have a sample that uses JDBCJobStore which doesn't work but this sample works fine with RAMJobStore.

Just when I choose JDBCJobStore and exception get raised.

I am using quartz-1.6.5.

code:

package test;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;



public class ReportRunner {
    public static void main(String[] args) {
        try {

            SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
            Scheduler sched = schedFact.getScheduler();
            sched.start();

            JobDetail jobDetail = null;
            SimpleTrigger trigger2 = null;

            jobDetail = new JobDetail("Income Report", "Report Generation",
                    QuartzReport.class);
            jobDetail.getJobDataMap().put("type", "FULL");
            jobDetail.setDurability(true);

            trigger2 = new SimpleTrigger("Income Report", "Report Generation");

            trigger2.setStartTime(new java.util.Date(
                    System.currentTimeMillis() + 4000));
            trigger2.setRepeatInterval(5000);
            trigger2.setRepeatCount(100);
            sched.scheduleJob(jobDetail, trigger2);



        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

package test;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class QuartzReport implements Job {

    public void execute(JobExecutionContext cntxt) throws JobExecutionException {
        System.out.println("Generating report - "
                + cntxt.getJobDetail().getJobDataMap().get("type"));

    }
}

config file:

org.quartz.scheduler.instanceName = Sched1
org.quartz.scheduler.instanceId = 1
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.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.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://192.168.0.4:3306/conference
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password =root
org.quartz.dataSource.myDS.maxConnections 5 

this the excpetion showd in runtime , it was logged


org.quartz.JobPersistenceException: Couldn't acquire next trigger: Field 'PRIORITY' doesn't have a default value [See nested exception: java.sql.SQLException: Field 'PRIORITY' doesn't have a default value]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:1778)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.acquireNextTrigger(JobStoreTX.java:1218)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:233)
* Nested Exception (Underlying Cause) ---------------
java.sql.SQLException: Field 'PRIORITY' doesn't have a default value
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.insertFiredTrigger(StdJDBCDelegate.java:3360)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:1771)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.acquireNextTrigger(JobStoreTX.java:1218)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:233)
547  [QuartzScheduler_MyClusteredScheduler-NON_CLUSTERED_MisfireHandler] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore  - Lock 'TRIGGER_ACCESS' retuned by: QuartzScheduler_MyClusteredScheduler-NON_CLUSTERED_MisfireHandler

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北音执念 2024-08-06 01:32:24

java.sql.SQLException:字段
“优先级”没有默认值

我想你可以通过上面的异常来判断问题出在哪里。

java.sql.SQLException: Field
'PRIORITY' doesn't have a default
value

I guess you can tell where the problem lies by seeing the exception above.

青衫负雪 2024-08-06 01:32:24

我尝试使用 Quartz 1.6.5,但没有找到任何结果,但是使用 Quartz 1.5,我猜想 1.6.5 中的 JDBC jobstore 可能存在一些错误。
穆罕默德

I tried with Quartz 1.6.5 and I did't found any result, but it with with Quartz 1.5., I guess there might be some bug in 1.6.5 for JDBC jobstore.
Mohammad

吹泡泡o 2024-08-06 01:32:24

我有一个类似的问题,这是我的错..因为我使用的是版本 2.1.1 并且我从 2.2.1 的文档创建了表,我更新了 Maven 中的版本,它现在工作正常。

I had a similar problem, and it was my bad.. because I was using version 2.1.1 and I created tables from docs of 2.2.1, I updated the version in Maven and it is working fine now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文