2017-07-19 80 views
0

我知道這是一個重複的問題。對不起,問。我在我的spring mvc應用程序中遇到這個錯誤。 這是我默認地將Impl文件引起:java.sql.SQLException:未找到列'localename'

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; 
    } 

} 

在試圖執行此我得到了如下的錯誤"Caused by: java.sql.SQLException: Column 'localename' not found"。所有其他字段正常工作。但對於localename只顯示其錯誤。這裏有什麼問題??請幫我..

對不起,我的英文不好

這是我的員工類

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 + "]"; 
} 
} 
+1

表'employee'是否有名爲'localename'的列?這顯然是首先要檢查錯誤消息是否說沒有這樣的列。 – Jesper

+0

@Jesper是的,它是 – Shanmugapriya

+0

@TanmayDelhikar ..當然tanmay ..我會編輯我的問題 – Shanmugapriya

回答

0

請檢查

SELECT * FROM Employee 

DESC Employee 

列名localename存在或不存在於表格中。同時檢查localename的數據類型。

0

您應該連接到數據庫和執行(一定要在正確的模式):

DESC employee; 

你需要100%確保列「localename」的名義在返回的表描述完全匹配,它不應該有下劃線或連字符。這可能只是您創建的表格上的拼寫錯誤。

0

如果列名localename不存在於表格然後添加列localname,然後檢查柱localname在HBM文件映射與否(如果使用休眠)。

相關問題