2012-12-20 5 views
0

명령 줄에서 실행되는 Java 프로젝트가 있습니다. 그것은 봄을 사용하고 있습니다. 현재 프로젝트는 mySQL입니다. 아래의 config.xml에서 볼 수 있습니다.JNDI 데이터 소스를 사용하기 위해 Java, Spring Project를 마이그레이션하는 방법

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

저는 회사에서 JNDI 데이터 소스를 사용하기 위해 MySQL을 사용하지 않도록 프로젝트를 변경하라고합니다.

다음은 당신과 함께 내 자바 코드는 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 외부에서 사용할 수 있습니까 ??

감사

+0

(처음에는 JNDI 튜토리얼을보고 접근법/코드를 제안합니다. 질문이 남아 있으면 더 좋은 질문을하게 될 것입니다.) –

+0

당신은 할 수 있습니다. 좋은 JNDI 튜토리얼에 내게 – techsjs2012

+0

JNDI를 사용하지 않습니다. 그러나 첫 번째 단계는 검색입니다. 확실히, 당신은 많은 쓰레기를 얻을 것이다 : 그러나 또한 많은 보석. 이 단계는 숙달이 아니라 오히려 익숙 함에 관한 것입니다. 실제로 답을 얻는 것보다 더 많은 질문을 만들면 나쁘지 않습니다. 그 질문 자체는 더 구체적이고 개별적으로 집중 될 수 있습니다. –

답변

관련 문제