我开发 jsf 应用程序。我有一个 MySQL Student 表,包含 30-40 列和 600 行。这是 StudentBean 中的代码:
@ManagedBean(name = "student")
@SessionScoped
public class StudentBean implements Serializable{
private List<Student> studentlist = new ArrayList<Student>();
private Student student = new Student();
private HtmlDataTable datatable;
private HtmlInputHidden studentnpm = new HtmlInputHidden();
private String querybynpm;
private String querybyangkatan;
private String status;
private String result;
public String init() {
try {
Class.forName(JurusanConection.getDriver());
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
Connection con = DriverManager.getConnection(JurusanConection.getUrl(),
JurusanConection.getUser_name(), JurusanConection.getPass_word());
String query = "SELECT * FROM student";
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(query);
while (rs.next()) {
Student students = new Student();
students.setNpm(rs.getString("npm"));
students.setNama(rs.getString("nama").toString());
//setter and getter
students.setTanggalregistrasi(rs.getString("tanggalregistrasi").toString());
students.setDosenwali(rs.getString("dosenwali").toString());
students.setEmail(rs.getString("email"));
students.setKelas(rs.getString("kelas"));
studentlist.add(students);
}
result="mahasiswa";
ps.close();
con.close();
} catch (SQLException e) {
setResult(null);
setStatus(e.getMessage());
}
return result;
}
我没有通过构造函数填充数据库,而是调用了 init() 方法。我收到一条错误消息 javax.faces.el.EvaluationException: java.lang.NullPointerException。但是,当我修改查询以限制 150 行显示的数量时,没有错误。任何人都可以弄清楚如何正确显示这 600 行。谢谢...