简体   繁体   中英

Caused by: java.sql.SQLException: Column 'localename' not found

I know this is a repeated question. Sorry for asking. I am having this error in my spring mvc application. This is my Impl file

public Map<String, String> employeelist() {
    Map<String, String> map = new HashMap<String, String>();
    List<Employee> lang1 = namedParameterJdbcTemplate.query("select * from 
     employee", new EmployeeMapper());
    for (int i = 0; i < lang1.size(); i++) {
        map.put(lang1.get(i).getLocalename(), lang1.get(i).getName());
    }
    return map;
}

 public static final class EmployeeMapper implements RowMapper<Employee> {

    public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
        Map<String, String> map = new HashMap<String, String>();
        Employee employee = new Employee();
        employee.setId(rs.getString("id"));
        employee.setName(rs.getString("name"));
        employee.setSalary(rs.getString("salary"));
        employee.setDesignation(rs.getString("designation"));
        employee.setLocalename(rs.getString("localename"));
        return employee;
    }

}

While trying to execute this i am getting an error like "Caused by: java.sql.SQLException: Column 'localename' not found" . All other fields are working correctly. But for localename only its showing the error. What is the problem here?? Please help me..

Sorry for my poor english

This is my employee class

package com.bct.internal.form.model;

public class Employee {
private String id;
private String name;
private String salary;
private String designation;
private String localename;

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getSalary() {
    return salary;
}

public void setSalary(String salary) {
    this.salary = salary;
}

public String getDesignation() {
    return designation;
}

public void setDesignation(String designation) {
    this.designation = designation;
}


public String getLocalename() {
    return localename;
}

public void setLocalename(String localename) {
    this.localename = localename;
}

@Override
public String toString() {
    return "Employee [ID=" + id + ", NAME=" + name + ", SALARY=" + salary + 
", LOCALE_NAME=" + localename + ", DESIGNATION=" + designation + "]";
}
}

Please check

SELECT * FROM Employee 

or

DESC Employee

The column name localename is present or not in the table. Also check the datatype of the localename .

You should connect to your database and execute (be sure to be in the correct schema):

DESC employee;

You need to be 100% sure that the name of the column 'localename' returned on the table description matches exactly, it should not have underscores or hyphens. This could just be a typo on the table you created.

如果表中不存在列名localename ,则添加列localname ,然后检查hbm文件中是否映射了列localname (如果使用了hibernate)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM