I'm developing a system with Java 8 and Spring Boot with JDBC accessing an Oracle base. When I make a query using the NamedParameterJdbcTemplate, it does not return any records, but if I copy the same query and search the Oracle client directly, the records return normally. Here is the search method:
public Optional<Objeto> busca(String campo4, String campo3, String campo2) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT CAMPO_1, ");
sql.append(" CAMPO_2, ");
sql.append(" CAMPO_3, ");
sql.append(" CAMPO_4, ");
sql.append(" CAMPO_5, ");
sql.append(" CAMPO_6 ");
sql.append("FROM TABELA_DO_BANCO ");
sql.append(" WHERE CAMPO_4 = :pCampo4 ");
sql.append(" AND CAMPO_2 = :pCampo2 ");
sql.append(" AND CAMPO_3 = :pCampo3 ");
return this.namedParameterJdbcTemplate.query(sql.toString(), new MapSqlParameterSource()
.addValue("pCampo4", campo4, Types.INTEGER)
.addValue("pCampo2", campo2)
.addValue("pCampo3", campo3)
, new ObjetoRowMapper())
.stream().findFirst();
}
Here is the description of the database:
I believe the problem is in WHERE with field FIELD_2 , because when I remove it from the query, the system returns the expected records. Does anyone have any idea what it is? Has anyone gone through this?
Hugs.