Ajay Takur
Ajay Takur

Reputation: 6236

BadSqlGrammarException in Spring jdbc template

I am using Jdbctemplate to retrieve a single record from the db.here is the method.

public Advocate queryPrimaryDetails(String regCaseType, String regNo, String regYear) throws SQLException {
        String sql = "select pet_adv,pet_adv_cd from civil_t where regcase_type=? and reg_no=? and reg_year=?";
        Advocate list = (Advocate) getJdbcTemplate().queryForObject(sql, new Object[]{Integer.valueOf(regCaseType),Integer.valueOf(regNo),Integer.valueOf(regYear)},new RowMapper<Object>() {
            public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException {
                return resultSet.next() ? new Advocate(resultSet.getInt("pet_adv_cd"), resultSet.getString("pet_adv"))
                        : null;
            }
        });
        System.out.println(list);
        return list;
    }

In my scenario, it is completely possible to NOT get a hit on my query so my question is how do I get around the following error message.

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select pet_adv,pet_adv_cd from civil_t where regcase_type=?]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "civil_t" does not exist

Upvotes: 3

Views: 1357

Answers (1)

user10244094
user10244094

Reputation:

The exception is raised from the underlying postgresql JDBC-driver, because the table civil_t is not found in the database you're connecting to.

Upvotes: 0

Related Questions