简体   繁体   English

在JDBCTemplate中从MySQL数据库检索数据时出错

[英]Error retrieving data from MySQL database in JDBCTemplate

I am trying to get data from mysql database. 我正在尝试从mysql数据库获取数据。

My method for EmployeeJDBCTemplate is 我的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;
}

And this is the error I got after running the program: 这是运行程序后出现的错误:

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

Can anybody help me? 有谁能够帮助我? Thank you in advance. 先感谢您。

Looks like employeeJDBCTemplate object is not initialize - is null. 看起来employeeJDBCTemplate对象未初始化-为null。 Have you initialize it. 您初始化了吗?

Please replace the below tag 请替换以下标签

<p:dataTable var="emp" value="#{employeeJDBCTemplate.getListEmployees()}">

with

<p:dataTable var="emp" value="#{employeeJDBCTemplate.listEmployees()}">

Also please check if you initialize the employeeJDBCTemplate. 另外,请检查是否初始化employeeJDBCTemplate。 template Initialization in Spring XML configuration or using annotations Spring XML配置或使用批注中的模板初始化

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

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