我想在java中显示从数据库获取值的记录,其中id=id(从getter方法将值插入数据库不起作用)

我想在java中显示从数据库获取值的记录,其中id=id(从getter方法将值插入数据库不起作用),java,mysql,jsp,Java,Mysql,Jsp,我创建了一个java文件名Attend.java public class Attend { String attend_id,studname,owner; public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; }public String getStudname() { return Studname; } publ

我创建了一个java文件名Attend.java

public class Attend {
String attend_id,studname,owner;

public String getOwner() {
    return owner;
}

public void setOwner(String owner) {
    this.owner = owner;

}public String getStudname() {
    return Studname;
}

public void setStudname(String Studname) {
    this.Studname = Studname;
}

public String getAttend_id() {
    return attend_id;
}

public void setAttend_id(String attend_id) {
    this.attend_id = attend_id;
}} ;
其他文件DAO文件AttendDao.java

, public class AttendDao {public static List<Attend> getAllRecords(){
    List<Attend> list=new ArrayList<Attend>();
        //Attend u1=null; 
    try{
        Connection con=DbConnector.getConnection();
        PreparedStatement ps=con.prepareStatement("select attend_id,studname,owner from attend_detail where owner=?");
        Attend u1 = null;
        //System.out.println(u1.getOwner());
        ps.setString(1,u1.getOwner());
        ResultSet rs=ps.executeQuery();
        while(rs.next()){
            Attend u=new Attend();
            u.setAttend_id(rs.getString("attend_id"));
            u.setStudname(rs.getString("studname"));
            u.setOwner(rs.getString("owner"));
            list.add(u);
        }
    }catch(SQLException e1){System.out.println("sql error:"+e1);
    }catch(Exception e){System.out.println(e);}
    return list;
    //}
}},
这是我的jsp view.jsp

<body>
<%@page import="com.attend.detail.AttendDao,com.attend.detail.Attend,java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<div class="container">

<h1>Attendance List</h1>

<%
 List<Attend> list=AttendDao.getAllRecords();
 request.setAttribute("list",list);
 %>

 <div class="table-responsive" width="100%">
 <table id="myTable" class="display table table-bordered" width="99%" >
 <thead>  
      <tr>  
        <th>Attend_id</th>  
        <th>Student_id</th>   
        <th>owner</th>
      </tr>  
    </thead>  
    <tbody>
    <c:forEach items="${list}" var="u">  
      <tr>  
        <td>${u.getAttend_id()}</td>  
        <td>${u.getStudentid()}</td> 
        <td>${u.getOwner()}</td>  
      </tr> 
      </c:forEach> 
    </tbody>  

    </table>
    </div></body>

出席名单
出席
学生证
主人
${u.getAttention_id()}
${u.getStudentid()}
${u.getOwner()}
它显示NullpointerException
如何解决这个问题。。请重新设置。

您需要在
参与u1=null
之后分配一些值,该值用
null
初始化

    Attend u1 = null; 
    //System.out.println(u1.getOwner());
    ps.setString(1,u1.getOwner());

因此,基本上,
u1
具有
null
,您需要分配
attribute
对象来纠正此问题

我怎样才能知道你需要分配什么?可能,您需要从list@BURHANUDDIN检查我的更新答案。@BURHANUDDIN您需要分配
new attain()
内存位置,以便能够使用
ul
方法和数据字段。@abcOfJavaAndCPP将解决问题,但这不是解决方案。我使用了attain u1=new attain()//System.out.println(u1.getOwner());ps.setString(1,u1.getOwner());但我会证明它不是重复的,先生。
    Attend u1 = null; 
    //System.out.println(u1.getOwner());
    ps.setString(1,u1.getOwner());