我需要在java中执行程序PL sql。
我的PL / SQL。
TYPE REF_CURSOR IS REF CURSOR;
PROCEDURE GET_REPORT( P_account_number_param IN VARCHAR2,
P_cycle_cut_param IN VARCHAR2,
P_from_date_param IN VARCHAR2,
P_to_date_param IN VARCHAR2,
P_last_requested_by_param IN VARCHAR2,
P_worker_id_param IN VARCHAR2,
P_requeset_type_param IN VARCHAR2,
P_INQUIRY OUT REF_CURSOR,
P_RESULT out varchar2);
当我执行抛出错误rs = (ResultSet) cstmt.getObject(8);
行
说明错误:列索引无效。
供应商代码:17003
我尝试了多种方法来获得索引1,2或8但不起作用。
爪哇
CallableStatement cstmt = conn.prepareCall(sql);
int paramIdx = 1;
// pass IN parameter
if (params != null)
for (int i = 0; i < params.length; i++) {
cstmt.setString(paramIdx++, params[i]);
}
// register result
cstmt.registerOutParameter(paramIdx++, OracleTypes.CURSOR);// index = 8
cstmt.registerOutParameter(paramIdx++, OracleTypes.VARCHAR);
cstmt.execute();
rs = (ResultSet) cstmt.getObject(8);
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
results = new ArrayList<Map<String, Object>>();
这是我的PL / sql:
PROCEDURE GET__REPORT(P_account_number_param IN VARCHAR2,
P_cycle_cut_param IN VARCHAR2,
P_from_date_param IN VARCHAR2,
P_to_date_param IN VARCHAR2,
P_last_requested_by_param IN VARCHAR2,
P_worker_id_param IN VARCHAR2,
P_requeset_type_param IN VARCHAR2,
P_INQUIRY OUT REF_CURSOR,
P_RESULT out varchar2) is
SQL_STRING VARCHAR2(5000);
BEGIN
BEGIN
--OPEN P_INQUIRY FOR
SQL_STRING := 'select a.account_number , a.cycle_cut , a.last_requested_by, a.last_requested_date ,
CASE a.app_status
WHEN ''I'' THEN ''Initial failed''
WHEN ''G'' THEN ''Generate failed''
WHEN ''C'' THEN ''Check-In failed''
WHEN ''F'' THEN ''Send fax failed''
WHEN ''S'' THEN ''Successful''
ELSE a.app_status
END as app_status
, c.email
,
CASE c.email_status
WHEN ''P'' THEN ''Wait''
WHEN ''Y'' THEN ''Success''
ELSE c.email_status
END as email_status
, d.fax_no
,
CASE d.fax_status
WHEN ''P'' THEN ''Wait''
WHEN ''Y'' THEN ''Success''
WHEN ''D'' THEN ''Fax failed''
WHEN ''F'' THEN ''Gen Billing failed''
WHEN ''N'' THEN ''Billing not found''
WHEN ''U'' THEN ''CD not available''
ELSE d.fax_status
END as fax_status
from
ecm_billing_tax a LEFT JOIN ecm_billing_req b
ON a.billing_tax_id = b.billing_tax_id
LEFT JOIN ecm_billing_tax_email c
ON b.billing_tax_email_id = c.billing_tax_email_id
LEFT JOIN ecm_billing_tax_fax d
ON b.billing_tax_fax_id = d.billing_tax_fax_id
Where a.account_number is not null ';
IF P_account_number_param IS NOT NULL THEN
SQL_STRING := SQL_STRING ||' and a.account_number = ''' ||P_account_number_param || '''';
END IF;
IF P_cycle_cut_param IS NOT NULL THEN
SQL_STRING := SQL_STRING ||' and a.cycle_cut = to_date(''' ||P_cycle_cut_param || ''',''DD/MM/YYYY'') ';
END IF;
IF P_from_date_param IS NOT NULL THEN
SQL_STRING := SQL_STRING ||' and trunc(a.last_requested_date) >= to_date(''' ||P_from_date_param || ''',''DD/MM/YYYY'') ';
END IF;
IF P_to_date_param IS NOT NULL THEN
SQL_STRING := SQL_STRING ||' and trunc(a.last_requested_date) <= to_date(''' ||P_to_date_param || ''',''DD/MM/YYYY'') ';
END IF;
IF P_last_requested_by_param IS NOT NULL THEN
IF P_last_requested_by_param = 'ECM Poltal' THEN
SQL_STRING := SQL_STRING ||' and a.last_requested_by = ''' ||P_worker_id_param || '''';
ELSE
SQL_STRING := SQL_STRING ||' and a.last_requested_by = ''' ||P_last_requested_by_param || '''';
END IF;
END IF;
IF P_requeset_type_param IS NOT NULL THEN
IF P_requeset_type_param = 'Fax' THEN
SQL_STRING := SQL_STRING ||' and b.billing_tax_fax_id is not null ';
ELSIF P_requeset_type_param = 'E-Mail' THEN
SQL_STRING := SQL_STRING ||' and b.billing_tax_mail_id is not null ';
END IF;
END IF;
OPEN P_INQUIRY FOR SQL_STRING;
P_RESULT := 1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
P_RESULT := 0;
WHEN TOO_MANY_ROWS THEN
P_RESULT := -1;
WHEN OTHERS THEN
P_RESULT := sqlerrm;
END;
END GET_REPORT;
请帮帮我 谢谢你。
答案 0 :(得分:0)
我见过“java.sql.SQLException:无效的列索引”主要是由于两个原因:
1) Setting column data using setXXXX(int coloumIndex) e.g. setInt(0) setString(0)
2) Getting column data using getXXX(int columnIndex) e.g. getInt(0) getString(0)
“java.sql.SQLException:无效列索引”的最常见原因是误认为列索引以“0”开头,如数组或字符串索引,但这不是真的,而是列索引以“1”开头,所以每当你尝试获取或设置列索引为“0”的列数据,您将得到“java.sql.SQLException:无效的列索引”。
检查是否要为各个索引分配params[i]
。另外,请检查OUT
方法中传递的getObject()
参数索引。它应该是8或9。