当前位置: 首页 > 知识库问答 >
问题:

如何在石英中使用SQLite?

王岳
2023-03-14

我试图在一个应用程序中使用quartz和SQLite。当我阅读这里的文档时,我注意到它们在可用的数据库中没有提到SQLite。他们说:

JDBCJobStore几乎可以与任何数据库一起工作,它已经被Oracle、PostgreSQL、MySQL、MS SQLServer、HSQLDB和DB2广泛使用。要使用JDBCJobStore,必须首先创建一组数据库表供Quartz使用。您可以在Quartz发行版的“docs/dbtables”目录中找到创建表的SQL脚本。

那么,从这个问题来看:使用哪个设置脚本来设置quartz sqlite表?我使用derby脚本作为sqlite脚本应用。

// and start it off
scheduler.start();

Map<String, String> map = new HashMap<>();
map.put("key", "value");

JobDataMap jdm = new JobDataMap(map);

JobKey key = new JobKey("job1", "key1");

 if(!scheduler.checkExists(key)){
     JobDetail job = newJob(HelloJob.class).withIdentity(key).storeDurably().usingJobData(jdm).build();
     addJob(scheduler, job);

     // Trigger the job to run now, and then repeat every 40 seconds
    Trigger trigger = newTrigger()
         .withIdentity("trigger1", "group1")
         .startNow()
            .forJob(job)
               .withSchedule(simpleSchedule()
                 .withIntervalInSeconds(40)
                 .repeatForever())            
         .build();

    // Tell quartz to schedule the job using our trigger
    scheduler.scheduleJob(trigger); // here is where I get an error
 }

Thread.sleep(60000);

scheduler.shutdown();
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.dataSource.SQLiteDB.driver = org.sqlite.JDBC
org.quartz.dataSource.SQLiteDB.URL = jdbc:sqlite:bota.db
org.quartz.dataSource.SQLiteDB.maxConnections = 30
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = SQLiteDB

我使用的是sqlite v-3.8.11.2和quartz v-2.2.2。这是我在日志中得到的:

org.quartz.JobPersistenceException: Couldn't store trigger 'group1.trigger1' for 'key1.job1' job:Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: org.quartz.JobPersistenceException: Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: java.sql.SQLException: not implemented by SQLite JDBC driver]]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1223)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$4.executeVoid(JobStoreSupport.java:1159)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3715)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3713)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3799)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.executeInLock(JobStoreTX.java:93)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1155)
    at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:932)
    at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:258)
    at javaapplication2.JavaApplication2.main(JavaApplication2.java:174)
Caused by: org.quartz.JobPersistenceException: Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: java.sql.SQLException: not implemented by SQLite JDBC driver]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1396)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1205)
    ... 9 more
Caused by: java.sql.SQLException: not implemented by SQLite JDBC driver
    at org.sqlite.jdbc4.JDBC4ResultSet.unused(JDBC4ResultSet.java:320)
    at org.sqlite.jdbc4.JDBC4ResultSet.getBlob(JDBC4ResultSet.java:345)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBlob(NewProxyResultSet.java:285)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.getObjectFromBlob(StdJDBCDelegate.java:3190)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectJobDetail(StdJDBCDelegate.java:860)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1385)
    ... 10 more
BUILD STOPPED (total time: 11 seconds)

共有1个答案

邓俊英
2023-03-14

问题似乎是sqlite jdbc驱动程序不支持ResultSet.getBlob()方法。

但是quartz使用此方法检索分配给作业的JobDataMap。

如果您仍然希望将quartz与sqlite一起使用,可以扩展StdJDBCDelegate并检索/设置BLOB,如本答案中所建议的那样。

    null
 类似资料:
  • 问题内容: 我有一个Web应用程序,它使用诸如Struts和Hibernate之类的框架。目前,我正在使用Quartz为此应用程序开发调度程序。在编码时,我意识到在Quartz线程中无法使用Hibernate会话。 有人有使用石英作业类的hibernate会话的解决方案吗? 问题答案: 一种方法是使用一个类,该类在静态初始化程序中构建并通过getter 使它可用。您的Quartz作业可以创建一个a

  • 所以我有一个技术挑战我需要帮助。 一个大型项目正在使用Quartz调度程序调度一个作业,使其在每晚9点运行。 然而,调度的作业需要从属性文件中读取值,使用自动布线获取一些bean等。 当我使用@autowired和@value注释时,我发现这些值为空。 问题是Quartz在spring容器外部使用创建JobDetail对象。可以在下面的代码中看到。 因此,包装的对象无法使用Spring访问属性文件

  • 如何禁用Quartz日志记录?Quartz正在我的控制台上打印INFO语句。我试图用log4j中的以下语句禁用它。属性文件

  • 问题内容: 似乎Quartz Scheduler每秒可以运行的作业数量受到限制。在我们的方案中,我们每秒大约有20个作业,可以进行24x7的启动,而石英可以很好地完成每秒10个作业(对于JDBC支持的JobStore,它具有100个石英线程和100个数据库连接池大小),但是,当我们将其增加到20个时每秒的作业数量,石英变得非常非常慢,与实际的计划时间相比,石英的触发作业非常晚,从而导致许多失火,并

  • 我正在使用带有TerracottaJobStore Class的石英调度程序来每5分钟调度一次作业。我的工作配置是: 组织。石英jobStore。class=org。陶土。石英EnterpriseTerracottaJobStore组织。石英jobStore。tcconfig=localhost:9510 org。石英线程池。线程数=25 我有一个附加了5000个触发器的单个作业,然后该作业被安排

  • 问题内容: 有没有办法将石英作为基础调度程序? 我可以想到两件事,但都需要做一些工作: 创建一个将解析注解并注册石英作业的自定义 实施委托石英的工具。 问题是:以上两个选项是否已经编写过,是否还有另一个选项? 问题答案: 我最终制作了自己的弹簧石英“桥”。我打算建议将其作为春季的改进。 首先,我创建了一个新注释,该注释将放置在实现quartz Job接口的类上: (请注意原型作用域-石英假定每个作