我正在尝试从mysql数据库中获取数据。
我的EmployeeJDBCTemplate方法是
public List<Employee> getListEmployees() {
String sql = "select * from testemp";
List<Employee> listEmp = jdbcTemplaeObject.query(sql, new RowMapper<Employee>() {
@Override
public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
Employee emp = new Employee();
emp.setSn(rs.getInt("sn"));
emp.setID(rs.getInt("ID"));
emp.setName(rs.getString("name"));
emp.setCheckin(rs.getString("checkin"));
emp.setCheckout(rs.getString("checkout"));
emp.setBreakstart(rs.getString("breakstart"));
emp.setBreakend(rs.getString("breakend"));
return emp;
}
});
return listEmp;
}
这是我在运行程序后得到的错误:
Caused by: java.lang.NullPointerException
at att.user.dao.EmployeeJDBCTemplate.getListEmployees(EmployeeJDBCTemplate.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:183)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 77 more
任何人都可以帮助我吗?提前谢谢。
答案 0 :(得分:1)
看起来employeeJDBCTemplate
对象未初始化 - 为空。你有没有初始化它。
答案 1 :(得分:1)
请替换以下标记
<p:dataTable var="emp" value="#{employeeJDBCTemplate.getListEmployees()}">
与
<p:dataTable var="emp" value="#{employeeJDBCTemplate.listEmployees()}">
另外请检查您是否初始化employeeJDBCTemplate。模板在Spring XML配置中初始化或使用注释