0
我有一个从命令行运行的Java项目。它使用Spring。目前我的项目是mySQL。使用可以从config.xml下面看到如何迁移Java,Spring项目以使用JNDI数据源
<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数据源。
下面是我与你的Java代码可以使用的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之外的?
感谢
(首先看到一个JNDI教程,并提出一个方法/代码,然后,如果问题依然存在,他们可能会提出更好的问题。) – 2012-12-20 17:38:51
我对一个好的JNDI教程 – techsjs2012
我不使用JNDI。但第一步是搜索。当然,你会得到很多垃圾,但也是一些宝石。这个阶段不是关于掌握,而是关于熟悉。它实际上并不坏,如果它创造了更多的问题而不是它的答案 - 那些问题本身会更具体,并且可以单独集中。 – 2012-12-20 17:46:35