如何使Custom Deployer将数据写入MS SQL数据库? [英] How to make a Custom Deployer to write data to MS SQL database?
问题描述
我已在config/cd_deployer_conf.xml的默认处理器中添加了一个自定义模块:
I've added a custom module in the default processor in config/cd_deployer_conf.xml:
<Processor Action="Deploy" Class="com.tridion.deployer.Processor">
...
<Module Type="MyCustomModuleDeploy" Class="com.tridion.new.extensions.MyCustomModule">
</Module>
</Processor>
该模块的代码如下所示:
The code for the module looks something like this:
public class MyCustomModule extends com.tridion.deployer.modules.PageDeploy {
static Logger logger = Logger.getLogger("customDeployerFirst");
public MyCustomModule(Configuration config, Processor processor)
throws ConfigurationException {
super(config, processor);
// TODO Auto-generated constructor stub
}
public void processPage(Page page, File pageFile) throws ProcessingException {
// TODO Auto-generated method stub
Date d = new Date();
log.info("WORKING");
log.info("Page ID: " + page.getId().toString());
log.info("Publication date: "+ d.toString());
}
}
每次发布页面时,我都会在日志文件中获得所需的信息.
In my log file I get the info I wanted, every time a page is published.
下一步,我要在先前创建的表中将页面ID和发布日期写入Microsoft SQL数据库.我怎样才能做到这一点?如何从MyCustomModule访问数据库表?
What I want to do next is to write the page ID and publication date to my Microsoft SQL database, in a table I previously created. How can I do that? How can I access the database table from MyCustomModule?
谢谢
推荐答案
好,所以我在这里为解决我的问题所做的正是Quirijn的建议.使用JDBC驱动程序连接到我的数据库,然后执行sql更新查询:
Ok, so what I did here to solve my problem is exactly what Quirijn suggested. Used the JDBC driver to connect to my database and then executed an sql update query:
int sqlStatement = st.executeUpdate("insert into Pages values ('" + page.getId().toString()+ "', '" + ... + "')");
这样,每次发布Page时,一些数据都会写入我的数据库中.
This way each time a Page is published some data will be written to my database.
这篇关于如何使Custom Deployer将数据写入MS SQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!