大家好,我在运行代码时遇到上述异常。
这是我的类(class)。
package com.bct.internal.form.model;
public class Dept {
public String deptno;
public String deptname;
public String location;
public String getDeptno() {
return deptno;
}
public void setDeptno(String deptno) {
this.deptno = deptno;
}
public String getDeptname() {
return deptname;
}
public void setDeptname(String deptname) {
this.deptname = deptname;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
@Override
public String toString() {
return "Dept [DEPTNO=" + deptno + ", DNAME=" + deptname + ", LOC=" + location + ", ]";
}
}
我的 impl 文件是
@Override
public Map<String, String> practicelist() {
Map<String, String> map = new HashMap<String, String>();
List<Dept> lang1 = namedParameterJdbcTemplate.query("select * from dept", new DeptMapper());
for (int i = 0; i < lang1.size(); i++) {
map.put(lang1.get(i).getDeptno(), lang1.get(i).getDeptname());
}
return map;
}
public static final class DeptMapper implements RowMapper<Dept> {
@Override
public Dept mapRow(ResultSet rs, int rowNum) throws SQLException {
Map<String, String> map = new HashMap<String, String>();
Dept dept = new Dept();
dept.setDeptname(rs.getString("deptname"));
dept.setDeptno(rs.getString("deptno"));
dept.setLocation(rs.getString("location"));
return dept;
}
}
当尝试执行代码时,我收到类似“ERROR GlobalExceptionHandler.defaultErrorHandler -1 - [URL] : http://localhost:8082/internalhost/userSearch/107 org.springframework.jdbc.BadSqlGrammarException:PreparedStatementCallback;错误的 SQL 语法 [select * from dept];嵌套异常是 java.sql.SQLException: 无效的列名"
这是我的数据库表 image
最佳答案
错误表明列名称无效。您可以验证数据库表列与 RowMapper 结果集 getter 完全匹配吗?
关于java - BadSqlGrammarException :Caused by: java. sql.SQLException:列名无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372685/