如何迁移 Java、Spring 项目以使用 JNDI 数据源 [英] How do Migrate Java, Spring Project to use JNDI datasources

查看:29
本文介绍了如何迁移 Java、Spring 项目以使用 JNDI 数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从命令行运行的 Java 项目.它正在使用Spring.目前我的项目是 mySQL.使用可以从下面的config.xml中看到

I have a Java project that runs from the command line. It is using Spring. At the current time my project is mySQL. Use can see from the config.xml below

<bean id="mysqldataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="mysqldataSource.url" />
    <property name="username" value="mysqldataSource.username" />
    <property name="password" value="mysqldataSource.password" />
</bean>

我的公司要求我将项目从使用 MySQL 更改为使用 JNDI 数据源.

My firm is asking me to change the project from using MySQL to use a JNDI Data source.

下面是我的java代码,你可以看到使用的是jdbcTemplate:

Below is my java code with you can see is using jdbcTemplate:

public class DisasterReliefMySQLImpl extends JdbcTemplate implements
        DisasterReliefMySQL {

    private static Log log = LogFactory.getLog(DisasterReliefMySQLImpl.class
            .getName());

    String querySQL;
    int counter = 0;

    public int getCounter() {
        return counter;
    }

    private String getQuerySQL() {
        return querySQL;
    }

    private void setQuerySQL(String querySQL) {
        this.querySQL = querySQL;
    }

    DisasterReliefMySQLImpl(DataSource ds) {
        super(ds);
    }


    DisasterReliefMySQLImpl(DataSource ds, String querySQL) {
        super(ds);
        setQuerySQL(querySQL);
    }

    public int updateDonation(String id) {
        Long eTime = System.currentTimeMillis() / 1000;

        String updateSQL = "update uft_donation set sent_to_mbs="
                + eTime.toString() + " where  donation_id =" + id;

        return (int) this.update(updateSQL);
    }

    public List<Donation> returnResults() {
        log.debug("Starting returnResults...");

        List<Donation> Donations = new ArrayList<Donation>();

        List<Map<String, Object>> rows = this.queryForList(getQuerySQL());

        counter = 0;

        for (Map row : rows) {
            Donation d = new Donation();

            d.setDonationID((Long) row.get("donation_id"));
            d.setCCTransactionNumber((String) row.get("txn_id"));
            d.setProgramCode((String) row.get("gl_code"));
            d.setLastName((String) row.get("billing_last_name"));
            d.setFirstName((String) row.get("billing_first_name"));
            d.setAmount((String) row.get("mc_gross"));
            d.setAddressLine1((String) row.get("billing_street1"));
            d.setAddressLine2((String) row.get("billing_street2"));
            d.setCity((String) row.get("billing_city"));
            d.setState((String) row.get("zone_code"));
            d.setZipCode((String) row.get("billing_postal_code"));
            d.setCountry((String) row.get("country_name"));

            Donations.add(d);
            counter++;
        }

        log.debug(counter + " Donation(s) loaded");
        return Donations;
    }

}

谁能告诉我如何更改它以使用 JNDI 数据源.我还需要某处的 JNDI 服务用于数据库池吗?我们有带有数据源的 JBoss AS7,我可以从 JBoss 外部使用它吗??

Can someone please tell me how to change this to use a JNDI datasource. Also do I need a JNDI service somewhere for the database pooling?? We have JBoss AS7 with datasources in it can I use that from outside JBoss??

谢谢

推荐答案

在网上搜索jboss external jndi"发现这个

Found this searching the web for "jboss external jndi"

http:///www.engfers.com/2008/08/07/exposing_accessing-jboss-jndi-objects_datasources-from-an-external-jvm/

看起来像你想要的.使用您最喜欢的搜索引擎能找到的东西真是太棒了 ;)

Looks like what you're after. It's amazing what you can find with your favorite search engine ;)

这篇关于如何迁移 Java、Spring 项目以使用 JNDI 数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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