2010-10-28 30 views
0
public class TestProcedure extends StoredProcedure { 

TestProcedure(BasicDataSource dataSource, String procName) { 
    this.setDataSource(dataSource); 
    this.setSql(procName); 
    this.declareParameter(new SqlParameter("@test", Types.INTEGER)); 
} 

public List<Detail> executeProcedure(Integer studentId) { 
    Map inParams = new HashMap(); 
    inParams.put("@test", studentId); 
    this.compile(); 
    List<Detail> details = new ArrayList<Detail>(); 
    try { 
     ArrayList<LinkedHashMap<String, Object>> list = (ArrayList<LinkedHashMap<String, Object>>) execute(inParams).get("#result-set-1"); 
     for (LinkedHashMap<String, Object> linkedHashMap : list) { 
      Detail detail = new Detail(); 
      detail.setStudent_id((Integer) linkedHashMap.get("student_id")); 
      detail.setStudent_name((String) linkedHashMap.get("student_name")); 
      detail.setStudent_marks((Double) linkedHashMap.get("student_marks")); 
      details.add(detail); 
     } 
    } catch (Exception e) { 
     System.out.println("Error Man : " + e); 
    } 
    return details; 
} 

}建議推廣代碼在Spring中調用存儲過程

以上是通過調用春SP任何人都可以提出一個總體結構爲它。有些抽象類和接口的代碼....

回答

0

查看JPA,iBatis或Hibernate。所有的都是包含在Spring中的實現的ORM數據訪問包。我使用iBatis,但我確定3個都沒問題