Altough I have only 4 placeholders, I am getting the error Missing IN or OUT parameter at index:: 5 below is the jpql and the method I am using the setParameters.
private static final String TIMESTAMP_FORMAT = "'ddmmyyyy hh24:mi:ss'";
JPQL
private static final String SQL_GET_EOD_LIST = "SELECT tr.*, txn.accounting_code, txn.accounting_explanation, txn.is_financial, "
+ "txn.send_to_statement, txn.affected_limit, txn.FINANCIAL_EFFECT "
+ "FROM (SELECT app_id, ch_id, NVL(str_id, 'MAIN') AS str_id, trn_desc, trn_type, bal_code, "
+ " SUM (dedicated_money) AS balance, NVL(SUM(str_fee), 0) AS fee "
+ " FROM WALLET.shopping_trn "
+ " WHERE create_date BETWEEN TO_DATE (?, " + TIMESTAMP_FORMAT + ") "
+ " AND TO_DATE (?, " + TIMESTAMP_FORMAT + ") "
+ " GROUP BY app_id, ch_id, str_id, trn_desc, trn_type, bal_code) tr, "
+ " WALLET.txn_def_lookup trn_lookup, "
+ " WALLET.txn_def txn "
+ " WHERE tr.trn_desc = trn_lookup.trn_desc "
+ " AND tr.bal_code = trn_lookup.bal_code "
+ " AND trn_lookup.txn_def_id = txn.ID "
+ " AND tr.balance > 0 "
+ "UNION ALL "
+ "SELECT tr.*, txn.accounting_code, txn.accounting_explanation, txn.is_financial, "
+ " txn.send_to_statement, txn.affected_limit, txn.FINANCIAL_EFFECT "
+ "FROM (SELECT app_id, ch_id, NVL(str_id, 'MAIN') AS str_id, trn_desc, trn_type, bal_code, "
+ " SUM (main_money) AS balance, NVL(SUM(str_fee), 0) AS fee "
+ " FROM WALLET.shopping_trn "
+ " WHERE create_date BETWEEN TO_DATE (?, " + TIMESTAMP_FORMAT + ") "
+ " AND TO_DATE (?, " + TIMESTAMP_FORMAT + ") "
+ " GROUP BY app_id, ch_id, str_id, trn_desc, trn_type, bal_code) tr, "
+ " WALLET.txn_def_lookup trn_lookup, "
+ " WALLET.txn_def txn "
+ " WHERE tr.trn_desc = trn_lookup.trn_desc "
+ " AND tr.bal_code = trn_lookup.bal_code "
+ " AND trn_lookup.txn_def_id = txn.ID "
+ " AND tr.balance > 0 ";
the method
@Override
public List<EodView> fetchEodData(final String targetDate, String logInfo) {
List<EodView> results;
final String startDate = targetDate + " 00:00:00";
final String endDate = targetDate + " 23:59:59";
String query = obtainEodDataQuery();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("fetchEodData SQL: {}",
EMoneyCorpUtil.sqlBindReplace4Log(LOGGER.isDebugEnabled(),
query, startDate, endDate));
}
results = getJdbcTemplate().query(query, ps -> {
ps.setString(1, startDate);
ps.setString(2, endDate);
ps.setString(3, startDate);
ps.setString(4, endDate);
}, new EodRowMapper());
return results;
}
I tried spacing the placeholders, changing the syntax of the sql query, I have read many questions but none of it answered my problem.
Thank you.
In:
You pass two bind parameters into the query when there are four placeholders that need bind values in your query. That may be the cause of the error.
You can pass
LocalDateTimevalues rather than strings:Your query repeats itself in the almost-identical sub-queries that you
UNIONtogether. You can use one query andUNPIVOT(untested as I do not have your tables or data):Then you only need to read the tables once and there are only two bind parameters.