Spring Boot query does not return records

Asked

Viewed 198 times

0

I am developing a system with Java 8 and Spring Boot with JDBC accessing an Oracle base. When I do a query, using Namedparameterjdbctemplate, it does not return any record, but if I copy this same query and do a direct search in the Oracle client, the records return normally. Follow 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();
}

Follows the description of the database:

Descrição da tabela

I believe the problem lies in WHERE with the countryside CAMPO_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 it?

Hugs.

  • Where is the CAMPO_8?

  • Actually it is CAMPO_2, already corrected the post. Thank you.

  • 2

    Inspects the value that is in the field variable 2. Also, put the query you ran on the outside, because if the problem is in the Java query, it is probably relative to the value of the fields you injected in the query.

  • @Giulianabezerra inspected and the value is normal.

  • Include the query you are performing outside the application, as requested by @Giulianabezerra.

  • Follow sql taken directly from code: SELECT CAMPO_1, CAMPO_2, CAMPO_3, CAMPO_4, CAMPO_5, CAMPO_6 FROM SDE_PARAM_VALID_CRM WHERE CAMPO_4 = 112 AND CAMPO_2 = 337941320001 AND CAMPO_3 = 'AC';

  • Are you sure this query is running? Note that the column CAMPO_2 is the type VARCHAR2 and you’re comparing it to a numerical value.

  • So I put the Types.VARCHAR in the addValue of CAMPO_2, but did not resolve.

  • I believe that campo2, campo3 and campo4 should all be treated as Types.VARCHAR2 or Types.CHAR as appropriate.

  • @Piovezan I couldn’t find the Types.VARCHAR2 and treated as Types.CHAR but it didn’t work.

  • @Wellingtongonçalves They were just suggestions, I don’t know the framework.

  • @Piovezan Aah yes, thank you very much kkkk, but I tried to put all the Types but none worked :(

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.