简体   繁体   English

原因:java.sql.SQLException:找不到列'localename'

[英]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. 我的spring mvc应用程序中出现此错误。 This is my Impl file 这是我的Impl文件

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" . 尝试执行此操作时,出现类似"Caused by: java.sql.SQLException: Column 'localename' not found" All other fields are working correctly. 所有其他字段均正常工作。 But for localename only its showing the error. 但是对于localename仅显示错误。 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. 表中是否存在列名localename Also check the datatype of the localename . 还要检查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. 您需要100%确保表描述中返回的列'localename'的名称完全匹配,并且不应带有下划线或连字符。 This could just be a typo on the table you created. 这可能只是您创建的表上的错字。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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