gpt4 book ai didi

java - 如何在 Quartz 中使用 SQLite?

转载 作者:行者123 更新时间:2023-12-02 03:41:33 32 4
gpt4 key购买 nike

我正在尝试在应用程序中将quartz与SQLite结合使用。当我阅读文档here时我注意到他们在可用的数据库中没有提到 SQLite。他们说:

JDBCJobStore works with nearly any database, it has been used widely with Oracle, PostgreSQL, MySQL, MS SQLServer, HSQLDB, and DB2. To use JDBCJobStore, you must first create a set of database tables for Quartz to use. You can find table-creation SQL scripts in the “docs/dbTables” directory of the Quartz distribution.

所以,从这个问题来看:Which setup script to use for setting up quartz sqlite table?我使用 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();

我的quartz.properties是这样的:

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)

最佳答案

问题似乎是 sqlite jdbc 驱动程序 does not support the method ResultSet.getBlob() .

但是quartz使用这个方法来检索JobDataMap分配给作业。

如果您仍然想将quartz与sqlite一起使用,您可以扩展 StdJDBCDelegate并像建议的 in this answer 一样检索/设置 blob .

乍一看,您似乎只需要重写方法

  1. StdJDBCDelegate.getObjectFromBlob() 和
  2. StdJDBCDelegate.getJobDataFromBlob()

由于我不确定以后是否会出现更多问题(例如,您可以看到 sqlite jdbcdriver 有更多 unsupported ResultSet methods ),我宁愿建议使用开箱即用的数据库。

关于java - 如何在 Quartz 中使用 SQLite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36779788/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com