大家好,我在運行我的代碼時遇到了上述異常。BadSqlGrammarException:導致:java.sql.SQLException:列名無效
這是我的課。
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 + ", ]";
}
}
和我實現了一套文件
@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
嘗試'選擇deptname,deptno,從部門的位置' –
@ElliottFrisch謝謝你的回覆:)我已經嘗試過..仍顯示相同的錯誤。 – Shanmugapriya