使用Quartz获取数据库连接 [英] Getting Database Connection using Quartz

查看:803
本文介绍了使用Quartz获取数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我需要在计划过程中插入数据并检索数据.尽管我可以创建自己的连接类并可以完成工作,但我想知道是否有一种方法可以使用Quartz API.

I have a requirement where i need to insert data and retrieve the same during my scheduling process.Though i can create my own connection class and can do the work but i am wondering is there a way to obtain a data base connection using Quartz API.

由于Quartz有效地进行了数据库连接和处理,所以我的目的是使用定义良好的结构来代替创建自己的结构.

Since Quartz is efficiently doing data base connection and handling so my intention was to use a well defined structure in stead of creating my own.

我在Quartz中看到了以下代码

I saw the following code in the Quartz

conn = DBConnectionManager.getInstance().getConnection(
                    getDataSource());

但是我不确定这种方法获得连接的效果如何.或者是否有任何好的示例/资源来创建高效的数据库连接类.

but i am not sure how good this approach is to obtain the connection.Or is there any good example/resource to create an efficient database connection class.

org.quartz.scheduler.instanceName=QuartzScheduler
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.threadPool.threadCount=7
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.MSSQLDelegate
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://localhost:3306/quartz
org.quartz.dataSource.myDS.user=root
org.quartz.dataSource.myDS.password=root
org.quartz.dataSource.myDS.maxConnections=5

推荐答案

通过命名属性文件中定义的数据源,您可以利用Quartz获得连接,例如

You can get connection utilizing Quartz by naming the data-source you have defined in your property file like

conn = DBConnectionManager.getInstance().getConnection("myDS");

此处myDS是您在属性文件中定义的数据源的名称

here myDS is the name of the data source you have defined in your property file

但是,由于您使用的是石英的基础数据池,因此请确保关闭连接,以使其回到池中.

but since you are using the underlying data pool of quartz make sure that you close the connection so that it should get back to the pool.

这只是基于我对Quartz的了解以及如何获得连接的概述.

This is just an outline based on my knowledge of Quartz and how it get connection.

这篇关于使用Quartz获取数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆