【发布时间】:2019-01-25 21:10:14
【问题描述】:
我正在使用 Jdbctemplate 从 db 中检索单个记录。方法如下。
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;
}
在我的情况下,我的查询完全有可能没有得到点击,所以我的问题是如何绕过以下错误消息。
HTTP 状态 500 - 请求处理失败;嵌套异常是 org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;错误的 SQL 语法 [select pet_adv,pet_adv_cd from Civil_t where regcase_type=?];嵌套异常是 org.postgresql.util.PSQLException: ERROR: 关系“civil_t”不存在
【问题讨论】:
-
尝试在表名
select pet_adv,pet_adv_cd from "civil_t" ...或数据库名select pet_adv,pet_adv_cd from database.civil_t ...周围使用双引号 -
当我尝试在查询生成器中执行它时,同一数据库中的所有其他表都与此查询一起成功执行。问题不在于查询。
-
在表不成立前加前缀数据库名。
标签: java sql spring postgresql jdbc