繁体   English   中英

quartz.properties无法访问mysql:无法加载driverClass com.mysql.jdbc.Driver

[英]quartz.properties cant access mysql : Could not load driverClass com.mysql.jdbc.Driver

我正在努力解决此问题,我已经尝试运行一个小型测试来与我的mysql连接,并且它可以正常工作。但是当我尝试使用quartz.properties时,它无法访问mysql。

我确定我的jdbc mysql驱动程序很好。 除了使用quartz.properties外,我还可以访问我的mysql数据库。

我需要帮助。 我已经为此工作了几天。

这是我怀疑有问题的部分

#The details of the datasource specified previously  
org.quartz.dataSource.myDS.driver =com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL =jdbc:mysql://10.1.1.111:3306/somedatabase
org.quartz.dataSource.myDS.user =username
org.quartz.dataSource.myDS.password =somepassword
org.quartz.dataSource.myDS.maxConnections = 20

错误输出:

207 [main] INFO org.quartz.impl.StdSchedulerFactory  - Quartz scheduler 'MyScheduler' initialized   from default file in current working dir: 'quartz.properties'
 208 [main] INFO org.quartz.impl.StdSchedulerFactory  - Quartz scheduler version: 2.2.1
267 [main] DEBUG com.mchange.v2.resourcepool.BasicResourcePool  - incremented pending_acquires: 1
267 [main] DEBUG com.mchange.v2.resourcepool.BasicResourcePool  - incremented pending_acquires: 2
268 [main] DEBUG com.mchange.v2.resourcepool.BasicResourcePool  - incremented pending_acquires: 3
268 [main] DEBUG com.mchange.v2.resourcepool.BasicResourcePool  -   com.mchange.v2.resourcepool.BasicResourcePool@42af94c4 config: [start -> 3; min -> 1; max -> 20; inc   -> 3; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 0;    mox_resource_age -> 0; max_idle_time -> 0; excess_max_idle_time -> 0; destroy_unreturned_resc_time ->    0; expiration_enforcement_delay -> 0; break_on_acquisition_failure -> false;    debug_store_checkout_exceptions -> false]
269 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] WARN     com.mchange.v2.c3p0.DriverManagerDataSource  - Could not load driverClass com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)

这是我的石英代码

public class QuartzDaily {
static Logger log = Logger.getLogger("QuartzDaily");

public static void main(String[] args) throws ParseException, SchedulerException, IOException,  NoSuchAlgorithmException 
{
   //lines of codes to configure log
    DateFormat format3 = new SimpleDateFormat( "MM_dd_yyyy_HH_mm" );
    Date dateToday = new Date();
    String strToday= format3.format(dateToday); 

    BasicConfigurator.configure();
    PatternLayout pattern = new PatternLayout("%r [%t] %-5p %c %x - %m%n");
    FileAppender fileappender = new  FileAppender(pattern,"log\\QuartzScheduler_"+strToday+".txt");

    log.addAppender(fileappender);
    log.info("QuartzReport; main(): [** Starting scheduler services **]");

    //run quartz job
    quartzWeekly();


}

public static void quartzWeekly() throws SchedulerException{

  //some quartz job code

}

public static class TestJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        System.out.println("hello world");
    }   
}
}

下面是完整的代码,下面的代码不是我的,它来自随机教程站点。

#Skip Update Check  
#Quartz contains an "update check" feature that connects to a server to
#check if there is a new version of Quartz available  
org.quartz.scheduler.skipUpdateCheck: true

org.quartz.scheduler.instanceName =MyScheduler
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 4
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.threadPool.threadPriority = 5


#specify the jobstore used  
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false

#specify the TerracottaJobStore  
#org.quartz.jobStore.class = org.terracotta.quartz.TerracottaJobStore  
#org.quartz.jobStore.tcConfigUrl = localhost:9510  


#The datasource for the jobstore that is to be used  
org.quartz.jobStore.dataSource = myDS

#quartz table prefixes in the database  
org.quartz.jobStore.tablePrefix = qrtz_
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false

#The details of the datasource specified previously  
org.quartz.dataSource.myDS.driver =com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL =jdbc:mysql://10.1.1.11:3306/somedatabase
org.quartz.dataSource.myDS.user =username
org.quartz.dataSource.myDS.password =somepassword
org.quartz.dataSource.myDS.maxConnections = 20

#Clustering
#clustering currently only works with the JDBC-Jobstore (JobStoreTX  
#or JobStoreCMT). Features include load-balancing and job fail-over  
#(if the JobDetail's "request recovery" flag is set to true). It is important to note that  
# When using clustering on separate machines, make sure that their clocks are synchronized  
#using some form of time-sync service (clocks must be within a second of each other).  
#See http://www.boulder.nist.gov/timefreq/service/its.htm.  
# Never fire-up a non-clustered instance against the same set of tables that any  
#other instance is running against.  
# Each instance in the cluster should use the same copy of the quartz.properties file.  

org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000

#Each server must have the same copy of the configuration file.  
#auto-generate instance ids.  
org.quartz.scheduler.instanceId = AUTO

#Note :  
#If a job throws an exception, Quartz will typically immediately  
#re-execute it (and it will likely throw the same exception again).  
#It's better if the job catches all exception it may encounter, handle them,  
#and reschedule itself, or other jobs. to work around the issue.  

我遇到了完全相同的问题,并通过在WEB-INF / lib中添加mysql连接器jar修复了它。 请确保在构建路径中将WEB-INF标记为源文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM