0

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>

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

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;
    }

}

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??

Thanks

techsjs2012
  • 1,737
  • 5
  • 25
  • 57
  • (First see a JNDI tutorial and propose an approach/code. Then, if questions remain, they'll likely make a better question.) –  Dec 20 '12 at 17:38
  • can you please point me to a good JNDI tutorial – techsjs2012 Dec 20 '12 at 17:43
  • I don't use JNDI. But the first step is a search. Sure, you'll get lots of junk: but also a number of gems. This stage isn't about mastery, but rather about familiarization. It's actually not bad if it *creates* more questions than it answers - those questions themselves will be more specific and can be focused on individually. –  Dec 20 '12 at 17:46
  • Also the post seems a bit unclear. It is to use/obtain a JDBC datasource *through* JNDI (and if so, from where) or to switch to a [different/JNDI] datasource entirely (and if so, what)? Even something as specific as the former would allow enough refinement to make this a better question (and possibly duplicate). –  Dec 20 '12 at 17:50
  • See here: http://stackoverflow.com/questions/9183321/how-to-use-jndi-datasource-provided-by-tomcat-in-spring – Stefan Dec 20 '12 at 18:39
  • Stefan the question is NOT how to do it inside the web project its how can I access it outside the web project – techsjs2012 Dec 20 '12 at 19:18
  • pst.... I did do a search and still can't find anything – techsjs2012 Dec 20 '12 at 19:20

1 Answers1

0

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 ;)

pap
  • 27,064
  • 6
  • 41
  • 46