2017-04-26 44 views
0

這下面的查詢而在SQL developoer執行返回一個單一的結果,但returing空列表而調用彈簧JDBC - getJdbcTemplate()的queryForList

List failedTxnList = getJdbcTemplate().queryForList(query, params); 

和PARAMS的值是[IM1691,VSIB01, 1/4/2017,25/4/2017]。請幫我看看這裏的問題。

select a.echeque_no,a.oid,a.echeque_date,d.name im_name,c.name vendor_name,a.corp_ref_no,b.hundi_date,a.echeque_amount,b.reversal_date, 
a.status_description 
from sbicorp_echeque_master a, sbi_gvf_vendor_txn_history b,sbi_gvf_vendor_master c, sbi_gvf_im_master d 
where a.debit_status = 'ERR.' 
    and LTRIM(RTRIM(a.corporate_id))= 'IM1691' 
    and LTRIM(RTRIM(a.businessline_id)) = 'VSIB01' 
    and trunc(a.echeque_date) BETWEEN TO_DATE ('1/4/2017', 'dd/mm/yyyy') AND TO_DATE ('25/4/2017', 'dd/mm/yyyy') 
    and a.corporate_id=d.im_code and a.businessline_id = c.vendor_code 
    and b.txn_type= 'Original Debit' 
    and a.echeque_no = b.reference_no 
    and substr(a.echeque_no,0,2) in ('CE','CR','CN','CZ') 
order by echeque_date desc -- CE01573281 
+0

這是我查詢的結果: –

+0

抱歉,無法發佈的結果,但結果有10列,一行 –

+0

ECHEQUE_NO OID ECHEQUE_DATE IM_NAME VENDOR_NAME CORP_REF_NO HUNDI_DATE ECHEQUE_AMOUNT REVERSAL_DATE STATUS_DESCRIPTION –

回答

0

我能看到的唯一事情是

trunc(a.echeque_date) BETWEEN TO_DATE ('1/4/2017', 'dd/mm/yyyy') AND TO_DATE ('25/4/2017', 'dd/mm/yyyy') 

嘗試更改日期字符串,以反映dequired格式

TO_DATE ('01/04/2017', 'dd/mm/yyyy') AND TO_DATE ('25/04/2017', 'dd/mm/yyyy') 
0

您獲取必須是某種類型的列表並將其必須實現rowMapper。 rowMapper告訴spring哪個列映射到哪個對象。

舉例如下。 圓模型類:這些字段是數據庫中的列。

public class Circle { 

    private int id; 

    private String name; 

    public int getId() { 
     return id; 
    } 
    public void setId(int id) { 
     this.id = id; 
    } 
    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.name = name; 
    } 

    public Circle(String name) { 
     super(); 
     this.name = name; 
    } 
    public Circle(int id, String name) { 
     super(); 
     this.id = id; 
     this.name = name; 
    } 
} 

定義列映射春天金環對象

public static final class CircleMapper implements RowMapper<Circle> { 
     public Circle mapRow(ResultSet resultSet, int arg1) throws SQLException { 
      return new Circle(resultSet.getInt("id"),resultSet.getString("name")); 

     } 
    } 

而在服務類調用該對象到數據庫列映射。

Circle circle = jdbcTemplate.queryForObject("SELECT * from circle where id = ?", new Object [] {id}, new CircleMapper()); 

對於你的情況,創建一個模型類與數據庫列。 創建一個映射器類,然後執行。