java.sql.SQLException:列索引无效..我们如何在以下查询中解决此错误?

时间:2015-03-14 10:41:58

标签: java sql jdbc prepared-statement

String  query_creditCardDtls = " SELECT A.FUND_ACC_TYPE , C.BANK_CODE, D.KEY_2, A.DDA_ISSUE  FROM DD300MB A, DD001MB C, CA840PB D WHERE A.BR_CD = C.BR_CD AND C.BR_CD = D.BR_CD AND A.BR_CD=? AND D.MOD_CD='DD' AND D.LANG_CD='EN' AND D.KEY_1 = 'ENTITY_ID' AND A.PAYING_BANK_ID = C.BANK_CODE AND A.REF_NO=? ";
ps=con.prepareStatement(query_creditCardDtls);
ps.setString(1,iBranchCode);
ps.setString(2,Txn_ref_no);
rs = ps.executeQuery();
if (rs.next())  {

    strFundACType = rs.getString(1);
    strPayingBankId = rs.getString(2);
    strEntityId = rs.getString(3);
    strDDAIssuedFor = rs.getString(4);
}

它给了我以下异常

java.sql.SQLException: Invalid column index 

但似乎没有索引错误请帮忙

1 个答案:

答案 0 :(得分:0)

第4列的类型可能与字符串不同。检查表定义。例如,如果第4列是整数,则使用getInt()而不是getString()

您也可以使用getString(columnname)。